Forum: Ruby-core [ruby-trunk - Bug #6566][Assigned] JSON.dump can generate invalid UTF-8 sequence

Posted by shyouhei (Shyouhei Urabe) (Guest)
on 2012-06-09 19:48
(Received via mailing list)
Issue #6566 has been reported by shyouhei (Shyouhei Urabe).

----------------------------------------
Bug #6566: JSON.dump can generate invalid UTF-8 sequence
https://bugs.ruby-lang.org/issues/6566

Author: shyouhei (Shyouhei Urabe)
Status: Assigned
Priority: Normal
Assignee: naruse (Yui NARUSE)
Category: M17N
Target version: 2.0.0
ruby -v: ruby 2.0.0dev (2012-06-09) [x86_64-linux]


=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
Posted by Nobuyoshi Nakada (nobu)
on 2012-06-10 00:23
(Received via mailing list)
Issue #6566 has been updated by nobu (Nobuyoshi Nakada).

File bug-6566.diff added

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.

----------------------------------------
Bug #6566: JSON.dump can generate invalid UTF-8 sequence
https://bugs.ruby-lang.org/issues/6566#change-27134

Author: shyouhei (Shyouhei Urabe)
Status: Assigned
Priority: Normal
Assignee: naruse (Yui NARUSE)
Category: M17N
Target version: 2.0.0
ruby -v: ruby 2.0.0dev (2012-06-09) [x86_64-linux]


=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
Posted by naruse (Yui NARUSE) (Guest)
on 2012-06-11 04:11
(Received via mailing list)
Issue #6566 has been updated by naruse (Yui NARUSE).


json is not only for 1.9, so nobu's patch is not acceptable.
I made https://github.com/flori/json/pull/139 .
----------------------------------------
Bug #6566: JSON.dump can generate invalid UTF-8 sequence
https://bugs.ruby-lang.org/issues/6566#change-27151

Author: shyouhei (Shyouhei Urabe)
Status: Assigned
Priority: Normal
Assignee: naruse (Yui NARUSE)
Category: M17N
Target version: 2.0.0
ruby -v: ruby 2.0.0dev (2012-06-09) [x86_64-linux]


=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
Posted by naruse (Yui NARUSE) (Guest)
on 2013-02-17 11:53
(Received via mailing list)
Issue #6566 has been updated by naruse (Yui NARUSE).

Target version changed from 2.0.0 to next minor


----------------------------------------
Bug #6566: JSON.dump can generate invalid UTF-8 sequence
https://bugs.ruby-lang.org/issues/6566#change-36427

Author: shyouhei (Shyouhei Urabe)
Status: Assigned
Priority: Normal
Assignee: naruse (Yui NARUSE)
Category: M17N
Target version: next minor
ruby -v: ruby 2.0.0dev (2012-06-09) [x86_64-linux]


=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
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.