Forum: Ruby-core JSON.parse can not handle tab in string

0fd80494679214743a967d583420a731?d=identicon&s=25 henrikhodne (Henrik Hodne) (Guest)
on 2013-08-08 01:15
(Received via mailing list)
Issue #8742 has been updated by henrikhodne (Henrik Hodne).


=begin
Confirm that tabs are not allowed in JSON strings according to the spec
(((<RFC4627|URL:http://tools.ietf.org/html/rfc4627#page-4>))).

Only characters that can be included unquoted are (({0x20}))-(({0x21})),
(({0x23}))-(({0x5B})) and (({0x5D}))-(({0x10FFFF})).

I do agree that the error message is a little confusing, though.
=end
----------------------------------------
Bug #8742: JSON.parse can not handle tab in string
https://bugs.ruby-lang.org/issues/8742#change-40979

Author: joejack (Joe Jack)
Status: Open
Priority: Low
Assignee:
Category: lib
Target version:
ruby -v: ruby 1.9.3p194 (2012-04-20) [x86_64-linux]
Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN


The following JSON file:
----
{
  "I am tab": "  "
}
----

does not parse when running the script:
----
require 'json'
JSON.parse IO::read 'tab.json'
----

the error message is:
----
/usr/local/lib/ruby/1.9.1/json/common.rb:148:in `parse': 743: unexpected
token at '{ (JSON::ParserError)
        "I am tab": "   "
}
'
        from /usr/local/lib/ruby/1.9.1/json/common.rb:148:in `parse'
        from parse.rb:2:in `<main>'
----

Taking out the quoted tab solves the problem.
If there is a quoted tab in a file, the error message shows the entire
document!
This topic is locked and can not be replied to.