ruby-changes:18906
From: tenderlove <ko1@a...>
Date: Mon, 21 Feb 2011 10:56:17 +0900 (JST)
Subject: [ruby-changes:18906] Ruby:r30931 (trunk): * ext/psych/lib/psych/json/stream.rb: do not emit custom tags in maps
tenderlove 2011-02-21 10:56:10 +0900 (Mon, 21 Feb 2011) New Revision: 30931 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=30931 Log: * 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. Modified files: trunk/ChangeLog trunk/ext/psych/lib/psych/json/stream.rb trunk/ext/psych/lib/psych/json/tree_builder.rb trunk/test/psych/json/test_stream.rb trunk/test/psych/test_json_tree.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 30930) +++ ChangeLog (revision 30931) @@ -1,3 +1,12 @@ +Mon Feb 21 10:54:29 2011 Aaron Patterson <aaron@t...> + + * 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@t...> * ext/psych/lib/psych/json/ruby_events.rb: DRY up ruby event handling Index: ext/psych/lib/psych/json/tree_builder.rb =================================================================== --- ext/psych/lib/psych/json/tree_builder.rb (revision 30930) +++ ext/psych/lib/psych/json/tree_builder.rb (revision 30931) @@ -17,7 +17,7 @@ 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 Index: ext/psych/lib/psych/json/stream.rb =================================================================== --- ext/psych/lib/psych/json/stream.rb (revision 30930) +++ ext/psych/lib/psych/json/stream.rb (revision 30931) @@ -11,11 +11,11 @@ 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 Index: test/psych/json/test_stream.rb =================================================================== --- test/psych/json/test_stream.rb (revision 30930) +++ test/psych/json/test_stream.rb (revision 30931) @@ -71,6 +71,26 @@ 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 }) Index: test/psych/test_json_tree.rb =================================================================== --- test/psych/test_json_tree.rb (revision 30930) +++ test/psych/test_json_tree.rb (revision 30931) @@ -31,6 +31,17 @@ 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) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/