Skip to content

Commit

Permalink
Merge: json::serialization: fix reading attributes from non-objects
Browse files Browse the repository at this point in the history
This error could arise when parsing invalid JSON strings (or non-object JSON values) and skipping the call to `deserialize`.

See @privat comment in #2291.

Pull-Request: #2295
Reviewed-by: Jean Privat <[email protected]>
Reviewed-by: Lucas Bajolet <[email protected]>
  • Loading branch information
privat committed Aug 26, 2016
2 parents 3718cfe + 2b1af32 commit 8b64731
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/json/serialization.nit
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,14 @@ class JsonDeserializer

redef fun deserialize_attribute(name, static_type)
do
assert not path.is_empty # This is an internal error, abort
if path.is_empty then
# The was a parsing error or the root is not an object
if not root isa Error then
errors.add new Error("Deserialization Error: parsed JSON value is not an object.")
end
return null
end

var current = path.last

if not current.keys.has(name) then
Expand Down

0 comments on commit 8b64731

Please sign in to comment.