[#69084] [Ruby trunk - Feature #11124] [Open] [PATCH] lib/*: use monotonic clock for timeouts — normalperson@...
Issue #11124 has been reported by Eric Wong.
5 messages
2015/05/06
[#69138] [Ruby trunk - Feature #11136] [PATCH] webrick: avoid fcntl module — nobu@...
Issue #11136 has been updated by Nobuyoshi Nakada.
3 messages
2015/05/12
[#69160] [Ruby trunk - Feature #11146] [PATCH] variable.c: initialize generic_iv_tbl at start — nobu@...
Issue #11146 has been updated by Nobuyoshi Nakada.
4 messages
2015/05/13
[#69175] Re: [Ruby trunk - Feature #11146] [PATCH] variable.c: initialize generic_iv_tbl at start
— Eric Wong <normalperson@...>
2015/05/13
nobu@ruby-lang.org wrote:
[ruby-core:69287] [Ruby trunk - Bug #10705] JSON::ParserError#message is wrong encoding (ASCII-8BIT)
From:
nobu@...
Date:
2015-05-21 05:13:46 UTC
List:
ruby-core #69287
Issue #10705 has been updated by Nobuyoshi Nakada.
You could make `ext/json/parser/parser.c` by `make srcs-ext`, if you were have `ragel` command.
----------------------------------------
Bug #10705: JSON::ParserError#message is wrong encoding (ASCII-8BIT)
https://bugs.ruby-lang.org/issues/10705#change-52544
* Author: Josh Cheek
* Status: Closed
* Priority: Normal
* Assignee:
* ruby -v: ruby 2.3.0dev (2015-01-06 trunk 49159) [x86_64-darwin13]
* Backport: 2.0.0: WONTFIX, 2.1: WONTFIX, 2.2: REQUIRED
----------------------------------------
JSON::ParserError#message is wrong encoding (ASCII-8BIT). I would expect the error to be whatever the internal encoding is (in my case, utf8), perhaps inspecting the string in the error message such that all characters would be valid in that encoding.
Here is an example of where it becomes an issue:
~~~ruby
# encoding: utf-8
require 'json' # => true
json = JSON.dump("√") # => "\"√\""
begin
result = JSON.parse(json)
puts "PARSED: #{result.inspect}"
rescue JSON::ParserError => e
`ruby -v` # => "ruby 2.3.0dev (2015-01-06 trunk 49159) [x86_64-darwin13]\n"
json.encoding # => #<Encoding:UTF-8>
e.message.encoding # => #<Encoding:ASCII-8BIT>
e.message # => "757: unexpected token at '\"\xE2\x88\x9A\"'"
puts "Could not parse #{json.inspect} because #{e.message}" # ~> Encoding::CompatibilityError: incompatible character encodings: UTF-8 and ASCII-8BIT
end
# ~> Encoding::CompatibilityError
# ~> incompatible character encodings: UTF-8 and ASCII-8BIT
# ~>
# ~> f9.rb:13:in `rescue in <main>'
# ~> f9.rb:5:in `<main>'
~~~
If the parsed string doesn't have a multibyte unicode character, it still happens, but fixes itself when it comes in contact with another string, since all its bytes are within the ASCII range.
Documented the actual use case and debugging [here](https://github.com/JoshCheek/seeing_is_believing/issues/46#issuecomment-69007428).
(side thought: should I open another bug since it generates invalid JSON?)
--
https://bugs.ruby-lang.org/