json icon indicating copy to clipboard operation
json copied to clipboard

Behaviour change between 2.5.1 and 2.6.0

Open stac47 opened this issue 2 years ago • 0 comments

Hello,

I just wanted to report that there was a slight behaviour change between those two versions. If we take the following:

 require "json"
 wrong_utf8 = "\x12\x34TESTING\xfe".force_encoding('BINARY')
 JSON.generate(wrong_utf8)

With json 2.5.1:

% bundle exec ruby reproducer.rb
/Users/stac/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/json-2.5.1/lib/json/common.rb:312:in `generate': "\xFE" from ASCII-8BIT to UTF-8 (Encoding::UndefinedConversionError)
        from /Users/stac/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/json-2.5.1/lib/json/common.rb:312:in `generate'
        from reproducer.rb:3:in `<main>'

With json 2.6.0:

% bundle exec ruby reproducer.rb
/Users/stac/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/json-2.6.0/lib/json/common.rb:312:in `generate': partial character in source, but hit end (JSON::GeneratorError)
        from /Users/stac/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/json-2.6.0/lib/json/common.rb:312:in `generate'
        from reproducer.rb:3:in `<main>'

This has also been tested with ruby 2.7.8 and 3.2.2.

Reading the changelog, I was not expecting such a change.

Regards,

stac47 avatar Jun 26 '23 14:06 stac47