Menu

#1 double quote string error

open
nobody
None
5
2005-03-10
2005-03-10
Anonymous
No

require 'test/unit'
require 'json/lexer'
require 'json/objects'

class ArrayTest < Test::Unit::TestCase
def test_array_to_json
array = Array.new
array[0] = 'bar'
array[1] = 1
array[2] = 2.7182818
array[3] = '"'

str = array.to_json
sarray = JSON::Lexer.new(str).nextvalue
assert(sarray.class == Array, "array was not
generated by deserialization")
assert(sarray[0] == 'bar', "error in serialization of a
string to JSON")
assert(sarray[1] == 1, "error in serialization of a
FixNum to JSON")
assert(sarray[2] == 2.7182818, "error in serialization
of a float to JSON")
assert(sarray[3] == '"', "error in serialization of a string
(doublu quote) to JSON")
end
end

% ruby arraytest.rb

Loaded suite arraytest
Started
E
Finished in 0.00333 seconds.

1) Error:
test_array_to_json(ArrayTest):
RuntimeError: Expected a ',' or ']'
/usr/lib/ruby/gems/1.8/gems/ruby-json-
1.1.1/lib/json/objects.rb:136:in `from_json'
/usr/lib/ruby/gems/1.8/gems/ruby-json-
1.1.1/lib/json/objects.rb:127:in `loop'
/usr/lib/ruby/gems/1.8/gems/ruby-json-
1.1.1/lib/json/objects.rb:127:in `from_json'
/usr/lib/ruby/gems/1.8/gems/ruby-json-
1.1.1/lib/json/lexer.rb:225:in `nextvalue'
arraytest.rb:15:in `test_array_to_json'

1 tests, 0 assertions, 0 failures, 1 errors

Discussion

  • Nobody/Anonymous

    Logged In: NO

    It error's patch....

    *** objects.rb.old 2005-03-10 18:17:40.876670753 +0900
    --- /usr/lib/ruby/gems/1.8/gems/ruby-json-
    1.1.1/lib/json/objects.rb 2005-03-10 18:17:43.825310037
    +0900
    ***************
    *** 70,76 ****
    |b|
    c = b.chr
    case c
    ! when /\\|\">/
    newstr << "\\" + c
    when "\b"
    newstr << "\\b"
    --- 70,76 ----
    |b|
    c = b.chr
    case c
    ! when /\\|\"/
    newstr << "\\" + c
    when "\b"
    newstr << "\\b"

     
  • Nobody/Anonymous

    Logged In: NO

    It error's patch....

    *** objects.rb.old 2005-03-10 18:17:40.876670753 +0900
    --- /usr/lib/ruby/gems/1.8/gems/ruby-json-
    1.1.1/lib/json/objects.rb 2005-03-10 18:17:43.825310037
    +0900
    ***************
    *** 70,76 ****
    |b|
    c = b.chr
    case c
    ! when /\\|\">/
    newstr << "\\" + c
    when "\b"
    newstr << "\\b"
    --- 70,76 ----
    |b|
    c = b.chr
    case c
    ! when /\\|\"/
    newstr << "\\" + c
    when "\b"
    newstr << "\\b"

     
  • Gabor Sebestyen

    Gabor Sebestyen - 2005-05-24

    Logged In: YES
    user_id=773782

    Here's a much simpler test to show the bug:

    require 'rubygems'
    require 'json/objects'
    puts "\"quoted\"".to_json

    It should print out \"quoted\" instead of "quoted"

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.