diff options
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | ext/psych/lib/psych/json/stream.rb | 4 | ||||
-rw-r--r-- | ext/psych/lib/psych/json/tree_builder.rb | 2 | ||||
-rw-r--r-- | test/psych/json/test_stream.rb | 20 | ||||
-rw-r--r-- | test/psych/test_json_tree.rb | 11 |
5 files changed, 43 insertions, 3 deletions
@@ -1,3 +1,12 @@ +Mon Feb 21 10:54:29 2011 Aaron Patterson <aaron@tenderlovemaking.com> + + * ext/psych/lib/psych/json/stream.rb: do not emit custom tags in maps + or sequences when emitting JSON. + * ext/psych/lib/psych/json/tree_builder.rb: do not emit custom tags in + sequences when emitting JSON. + * test/psych/json/test_stream.rb: tests for custom stream emits. + * test/psych/test_json_tree.rb: tests for JSON emits. + Mon Feb 21 10:05:10 2011 Aaron Patterson <aaron@tenderlovemaking.com> * ext/psych/lib/psych/json/ruby_events.rb: DRY up ruby event handling diff --git a/ext/psych/lib/psych/json/stream.rb b/ext/psych/lib/psych/json/stream.rb index 60c458ad38..5f0233515d 100644 --- a/ext/psych/lib/psych/json/stream.rb +++ b/ext/psych/lib/psych/json/stream.rb @@ -11,11 +11,11 @@ module Psych end def start_mapping anchor, tag, implicit, style - super(anchor, tag, implicit, Nodes::Mapping::FLOW) + super(anchor, nil, implicit, Nodes::Mapping::FLOW) end def start_sequence anchor, tag, implicit, style - super(anchor, tag, implicit, Nodes::Sequence::FLOW) + super(anchor, nil, implicit, Nodes::Sequence::FLOW) end def scalar value, anchor, tag, plain, quoted, style diff --git a/ext/psych/lib/psych/json/tree_builder.rb b/ext/psych/lib/psych/json/tree_builder.rb index 26fcb118d0..e4ab423dbb 100644 --- a/ext/psych/lib/psych/json/tree_builder.rb +++ b/ext/psych/lib/psych/json/tree_builder.rb @@ -17,7 +17,7 @@ module Psych end def start_sequence anchor, tag, implicit, style - super(anchor, tag, implicit, Nodes::Sequence::FLOW) + super(anchor, nil, implicit, Nodes::Sequence::FLOW) end def scalar value, anchor, tag, plain, quoted, style diff --git a/test/psych/json/test_stream.rb b/test/psych/json/test_stream.rb index 252535abaa..45d0219aad 100644 --- a/test/psych/json/test_stream.rb +++ b/test/psych/json/test_stream.rb @@ -71,6 +71,26 @@ module Psych assert_match(/["]two["]/, json) end + class Foo; end + + def test_json_dump_exclude_tag + @stream << Foo.new + json = @io.string + refute_match('Foo', json) + end + + class Bar + def encode_with coder + coder.represent_seq 'omg', %w{ a b c } + end + end + + def test_json_list_dump_exclude_tag + @stream << Bar.new + json = @io.string + refute_match('omg', json) + end + def test_time time = Time.utc(2010, 10, 10) @stream.push({'a' => time }) diff --git a/test/psych/test_json_tree.rb b/test/psych/test_json_tree.rb index 423a528b81..b694560367 100644 --- a/test/psych/test_json_tree.rb +++ b/test/psych/test_json_tree.rb @@ -31,6 +31,17 @@ module Psych assert_match(/['"]two['"]/, json) end + class Bar + def encode_with coder + coder.represent_seq 'omg', %w{ a b c } + end + end + + def test_json_list_dump_exclude_tag + json = Psych.to_json Bar.new + refute_match('omg', json) + end + def test_list_to_json list = %w{ one two } json = Psych.to_json(list) |