From 8fd84e66cafa983b4922208950e4572b4734aa91 Mon Sep 17 00:00:00 2001 From: Florian Frank Date: Tue, 20 Mar 2012 13:44:59 +0100 Subject: Use C implementation and better regexp for pure --- lib/json/pure/generator.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/json/pure/generator.rb b/lib/json/pure/generator.rb index 9141ae5..3d5f09f 100644 --- a/lib/json/pure/generator.rb +++ b/lib/json/pure/generator.rb @@ -255,8 +255,12 @@ module JSON # 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 -- cgit v1.2.1