json icon indicating copy to clipboard operation
json copied to clipboard

[json_pure] Caught Encoding::CompatibilityError incompatible encoding regexp match (ASCII-8BIT regexp with UTF-8 string)

Open chancancode opened this issue 12 years ago • 0 comments

I'm working on a refactor of Rails's JSON handler (rails/rails#12183). I noticed that when I run the tests with json/pure (the default is to use json/ext, but I want to make sure things work as expected with both), I get an "incompatible encoding regexp match" error. The test case basically boils down to this, reproducible in irb without Rails:

% irb
>> require 'json/pure'
=> true
>> JSON.parse(%({"matzue": "松江", "asakusa": "浅草"}), quirks_mode: true)
JSON::ParserError: Caught Encoding::CompatibilityError at '{"matzue": "松江",': incompatible encoding regexp match (ASCII-8BIT regexp with UTF-8 string)
    from /Users/godfrey/.rvm/gems/ruby-2.0.0-p195/gems/json-1.8.0/lib/json/pure/parser.rb:242:in `rescue in parse_string'
    from /Users/godfrey/.rvm/gems/ruby-2.0.0-p195/gems/json-1.8.0/lib/json/pure/parser.rb:213:in `parse_string'
    from /Users/godfrey/.rvm/gems/ruby-2.0.0-p195/gems/json-1.8.0/lib/json/pure/parser.rb:257:in `parse_value'
    from /Users/godfrey/.rvm/gems/ruby-2.0.0-p195/gem`s/json-1.8.0/lib/json/pure/parser.rb:121:in `parse'
    from /Users/godfrey/.rvm/gems/ruby-2.0.0-p195/gems/json-1.8.0/lib/json/common.rb:155:in `parse'
    from (irb):2
    from /Users/godfrey/.rvm/rubies/ruby-2.0.0-p195/bin/irb:16:in `<main>'

Another test case yields similar result.

The same test cases works fine with json/ext.

Looking at the JSON spec, it seems that {"matzue": "松江", "asakusa": "浅草"} should be valid json text. Can you C/D?

chancancode avatar Sep 14 '13 08:09 chancancode