ruby-changes:31390
From: tenderlove <ko1@a...>
Date: Wed, 30 Oct 2013 03:10:31 +0900 (JST)
Subject: [ruby-changes:31390] tenderlove:r43469 (trunk): * ext/psych/lib/psych/visitors/yaml_tree.rb: string subclasses should
tenderlove 2013-10-30 03:10:24 +0900 (Wed, 30 Oct 2013) New Revision: 43469 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43469 Log: * ext/psych/lib/psych/visitors/yaml_tree.rb: string subclasses should not be considered to be binary. Fixes Psych / GH 166 https://github.com/tenderlove/psych/issues/166 * test/psych/test_string.rb: test for fix Modified files: trunk/ChangeLog trunk/ext/psych/lib/psych/visitors/yaml_tree.rb trunk/test/psych/test_string.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 43468) +++ ChangeLog (revision 43469) @@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Oct 30 03:08:24 2013 Aaron Patterson <aaron@t...> + + * ext/psych/lib/psych/visitors/yaml_tree.rb: string subclasses should + not be considered to be binary. Fixes Psych / GH 166 + https://github.com/tenderlove/psych/issues/166 + + * test/psych/test_string.rb: test for fix + Tue Oct 29 23:01:18 2013 Masaki Matsushita <glass.saga@g...> * array.c (rb_ary_zip): some refactoring. Index: ext/psych/lib/psych/visitors/yaml_tree.rb =================================================================== --- ext/psych/lib/psych/visitors/yaml_tree.rb (revision 43468) +++ ext/psych/lib/psych/visitors/yaml_tree.rb (revision 43469) @@ -267,8 +267,7 @@ module Psych https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych/visitors/yaml_tree.rb#L267 def binary? string (string.encoding == Encoding::ASCII_8BIT && !string.ascii_only?) || string.index("\x00") || - string.count("\x00-\x7F", "^ -~\t\r\n").fdiv(string.length) > 0.3 || - string.class != String + string.count("\x00-\x7F", "^ -~\t\r\n").fdiv(string.length) > 0.3 end private :binary? @@ -301,6 +300,8 @@ module Psych https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych/visitors/yaml_tree.rb#L300 if ivars.empty? unless o.class == ::String tag = "!ruby/string:#{o.class}" + plain = false + quote = false end @emitter.scalar str, nil, tag, plain, quote, style else Index: test/psych/test_string.rb =================================================================== --- test/psych/test_string.rb (revision 43468) +++ test/psych/test_string.rb (revision 43469) @@ -20,6 +20,11 @@ module Psych https://github.com/ruby/ruby/blob/trunk/test/psych/test_string.rb#L20 assert_match(/---\s*"/, yaml) end + def test_cycle_x + str = X.new 'abc' + assert_cycle str + end + def test_dash_dot assert_cycle '-.' assert_cycle '+.' -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/