Closed Joseworks closed 8 years ago
You need to bump the version to 0.1.19 @Joseworks
@allolex please review, thank you.
def valid_json?(json)
begin
JSON.parse json
return true
rescue JSON::ParserError => e
return false
end
end
It's probably better to try to parse it as JSON, then fail over if it's not. That will eliminate other holes in the armor.
@allolex
That blows up, because just attempting to do:
begin
JSON.parse json
return true
rescue JSON::ParserError => e
return false
end
results on a different error:
rake aborted!
NoMethodError: undefined method `[]' for nil:NilClass
on:
@categories = CategoryCollection.new parsed_menu["categories"]
@Joseworks parsed_menu
should not be empty under any circumstances by the time it reaches that point. If there is no menu to parse, then there's a problem and the import should not happen at all.
With the code above:
parsed_menu = if valid_json?(opts[:menu])
JSON.parse opts[:menu]
else
opts[:menu]
end
raise ":menu cannot be empty" if opts[:menu].empty?
@allolex , the problem is not the parsed_menu being empty, the problem is that trying to run
if valid_json?(opts[:menu])
results on:
ArgumentError: strict_parse() expected a String or IO Object
which halts execution on the spot
Implements #1