Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #7883 (closed defect: fixed)

Opened 1 year ago

Last modified 1 year ago

[PATCH] Object.toJSON should be more liberal with spacing (for YAML compatibility)

Reported by: savetheclocktower Assigned to: sam
Priority: high Milestone: 1.x
Component: Prototype Version: edge
Severity: minor Keywords: 1.5.1 ready
Cc: savetheclocktower

Description

I'll let my irb session explain this one:

>> require 'yaml'
=> true
>> YAML.load("{ 'foo':'bar' }")
ArgumentError: syntax error on line 0, col 13: `'
        from /usr/local/lib/ruby/1.8/yaml.rb:133:in `load'
        from /usr/local/lib/ruby/1.8/yaml.rb:133:in `load'
        from (irb):3
>> YAML.load("{ 'foo': 'bar' }")
=> {"foo"=>"bar"}

Currently, Object.toJSON doesn't put these spaces in.

This is a trivial fix, but I've attached a patch anyway.

Attachments

json.diff (5.0 kB) - added by savetheclocktower on 04/23/07 22:13:58.
New patch that fixes Array#toJSON and Hash#toJSON (and updates the tests)

Change History

03/22/07 17:34:00 changed by mislav

  • keywords changed from 1.5.1 ready discuss to 1.5.1 ready.

I don't think there's any room for objections here

03/24/07 06:41:50 changed by Tobie

  • keywords changed from 1.5.1 ready to 1.5.1.

Agreed.

As per RFC 4627:

Insignificant whitespace is allowed before or after any of the six structural characters. [these are '[', '{', ']', '}', ':' and ',']

The current diff is missing the same changes for Hash.toJSON and Array.toJSON though. It'll be ready then.

04/23/07 22:13:58 changed by savetheclocktower

  • attachment json.diff added.

New patch that fixes Array#toJSON and Hash#toJSON (and updates the tests)

04/23/07 22:14:23 changed by savetheclocktower

  • cc changed from savetheclocktoewr to savetheclocktower.
  • keywords changed from 1.5.1 to 1.5.1 ready.

04/24/07 05:47:07 changed by Tobie

  • status changed from new to closed.
  • resolution set to fixed.

fixed in [6555]