json
json copied to clipboard
Behaviour change between 2.5.1 and 2.6.0
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,