summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-10-29 18:10:24 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-10-29 18:10:24 +0000
commite0c6dd91a450a47b701fb0a9d7fd908814651641 (patch)
tree88e035756faf814af1845afc049c3d5ba98a6ec1
parent887ff70f23e20081b424d1986988e005f8cce312 (diff)
* 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 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43469 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog8
-rw-r--r--ext/psych/lib/psych/visitors/yaml_tree.rb5
-rw-r--r--test/psych/test_string.rb5
3 files changed, 16 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 25354e3..ed3e15b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Wed Oct 30 03:08:24 2013 Aaron Patterson <aaron@tenderlovemaking.com>
+
+ * 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@gmail.com>
* array.c (rb_ary_zip): some refactoring.
diff --git a/ext/psych/lib/psych/visitors/yaml_tree.rb b/ext/psych/lib/psych/visitors/yaml_tree.rb
index f8bece6..65cbba0 100644
--- a/ext/psych/lib/psych/visitors/yaml_tree.rb
+++ b/ext/psych/lib/psych/visitors/yaml_tree.rb
@@ -267,8 +267,7 @@ module Psych
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
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
diff --git a/test/psych/test_string.rb b/test/psych/test_string.rb
index 025ef95..84326da 100644
--- a/test/psych/test_string.rb
+++ b/test/psych/test_string.rb
@@ -20,6 +20,11 @@ module Psych
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 '+.'