From a9c56c5ece54deaa05d7d2a584eaafb1891993c1 Mon Sep 17 00:00:00 2001 From: Rob Steward Date: Mon, 30 Mar 2015 18:47:24 -0400 Subject: don't assume any tag starting with 'str' is a string --- lib/psych/visitors/to_ruby.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/psych/visitors/to_ruby.rb b/lib/psych/visitors/to_ruby.rb index b68abb6..ea3ab1c 100644 --- a/lib/psych/visitors/to_ruby.rb +++ b/lib/psych/visitors/to_ruby.rb @@ -61,7 +61,7 @@ module Psych case o.tag when '!binary', 'tag:yaml.org,2002:binary' o.value.unpack('m').first - when /^!(?:str|ruby\/string)(?::(.*))?/, 'tag:yaml.org,2002:str' + when /^!(?:str|ruby\/string)(?::(.*))?$/, 'tag:yaml.org,2002:str' klass = resolve_class($1) if klass klass.allocate.replace o.value @@ -208,7 +208,7 @@ module Psych obj end - when /^!(?:str|ruby\/string)(?::(.*))?/, 'tag:yaml.org,2002:str' + when /^!(?:str|ruby\/string)(?::(.*))?$/, 'tag:yaml.org,2002:str' klass = resolve_class($1) members = {} string = nil -- cgit v1.2.1 From 3ed6bf733c6e2401780115b0cd64736eca5f2244 Mon Sep 17 00:00:00 2001 From: filialpails Date: Mon, 30 Mar 2015 19:34:25 -0400 Subject: add test --- test/psych/visitors/test_to_ruby.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/psych/visitors/test_to_ruby.rb b/test/psych/visitors/test_to_ruby.rb index c13d980..5c6ba2b 100644 --- a/test/psych/visitors/test_to_ruby.rb +++ b/test/psych/visitors/test_to_ruby.rb @@ -321,6 +321,13 @@ description: assert_equal %w{ foo foo }, list assert_equal list[0].object_id, list[1].object_id end + + def test_mapping_with_str_tag + mapping = Nodes::Mapping.new(nil, '!strawberry') + mapping.children << Nodes::Scalar.new('foo') + mapping.children << Nodes::Scalar.new('bar') + assert_equal({'foo' => 'bar'}, mapping.to_ruby) + end end end end -- cgit v1.2.1