lib/json/pure/generator.rb in json_pure-1.6.5 vs lib/json/pure/generator.rb in json_pure-1.6.6
- old
+ new
@@ -253,11 +253,15 @@
# Generates a valid JSON document from object +obj+ and returns the
# result. If no valid JSON document can be created this method raises a
# GeneratorError exception.
def generate(obj)
result = obj.to_json(self)
- if !@quirks_mode && result !~ /\A\s*(?:\[.*\]|\{.*\})\s*\Z/m
- raise GeneratorError, "only generation of JSON objects or arrays allowed"
+ unless @quirks_mode
+ unless result =~ /\A\s*\[/ && result =~ /\]\s*\Z/ ||
+ result =~ /\A\s*\{/ && result =~ /\}\s*\Z/
+ then
+ raise GeneratorError, "only generation of JSON objects or arrays allowed"
+ end
end
result
end
# Return the value returned by method +name+.