Bug #6566
closedJSON.dump can generate invalid UTF-8 sequence
Description
=begin
Look, in the following code JSON.dump outputs a sequence invalid as UTF-8.
-- encoding: utf-8 --¶
require 'json'
IO.popen('hexdump -C', 'w') do |fp|
JSON.dump(["\xea"], fp)
end
RFC4627 says that to encode JSON as a Unicode is a "SHALL". So this is an RFC violation.
=end
Files
Updated by nobu (Nobuyoshi Nakada) almost 12 years ago
- File bug-6566.diff bug-6566.diff added
=begin
A bit simpler, it seems wrong that
JSON.generate(["\xea"]).valid_encoding?
returns (({false})).
I think this would be a bug in json generator, but what should happen
in this case? Seems (({convert_UTF8_to_JSON_ASCII()})) wants to reject
invalid sequence.
=end
Updated by naruse (Yui NARUSE) almost 12 years ago
json is not only for 1.9, so nobu's patch is not acceptable.
I made https://github.com/flori/json/pull/139 .
Updated by naruse (Yui NARUSE) about 11 years ago
- Target version changed from 2.0.0 to 2.6
Updated by jeremyevans0 (Jeremy Evans) over 4 years ago
- Status changed from Assigned to Closed
I think this was fixed upstream last year: https://github.com/flori/json/commit/91a24ecac3d722bc3e545fdd0657ed225e91c2df