summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-08-24 14:20:11 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2011-08-24 14:20:11 -0700
commitfe65329ce9ece399d61dadf1610e342ff456654e (patch)
treeeaff6f7ef244df975f596914a8a214f5e94d02c9
parent95fc90723bb041134c8fe3be8714e8599664ce8b (diff)
downloadpsych-fe65329ce9ece399d61dadf1610e342ff456654e.tar.gz
* ext/psych/lib/psych/nodes/node.rb: default `to_yaml` encoding to be
UTF-8. * test/psych/test_encoding.rb: test yaml dump encoding.
-rw-r--r--CHANGELOG.rdoc6
-rw-r--r--lib/psych/nodes/node.rb2
-rw-r--r--test/psych/test_encoding.rb16
3 files changed, 23 insertions, 1 deletions
diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc
index babac95..03ec7bb 100644
--- a/CHANGELOG.rdoc
+++ b/CHANGELOG.rdoc
@@ -1,3 +1,9 @@
+Thu Aug 25 06:11:35 2011 Aaron Patterson <aaron@tenderlovemaking.com>
+
+ * ext/psych/lib/psych/nodes/node.rb: default `to_yaml` encoding to be
+ UTF-8.
+ * test/psych/test_encoding.rb: test yaml dump encoding.
+
Wed Jun 22 03:20:52 2011 Aaron Patterson <aaron@tenderlovemaking.com>
* ext/psych/lib/psych/visitors/to_ruby.rb: Fix cyclic references of
diff --git a/lib/psych/nodes/node.rb b/lib/psych/nodes/node.rb
index 7c040ec..2a5573a 100644
--- a/lib/psych/nodes/node.rb
+++ b/lib/psych/nodes/node.rb
@@ -41,7 +41,7 @@ module Psych
#
# See also Psych::Visitors::Emitter
def to_yaml io = nil, options = {}
- real_io = io || StringIO.new
+ real_io = io || StringIO.new(''.encode('utf-8'))
Visitors::Emitter.new(real_io, options).accept self
return real_io.string unless io
diff --git a/test/psych/test_encoding.rb b/test/psych/test_encoding.rb
index 029ff75..a341c47 100644
--- a/test/psych/test_encoding.rb
+++ b/test/psych/test_encoding.rb
@@ -40,6 +40,22 @@ module Psych
assert_match(/alias value/, e.message)
end
+ def test_to_yaml_is_valid
+ ext_before = Encoding.default_external
+ int_before = Encoding.default_internal
+
+ Encoding.default_external = Encoding::US_ASCII
+ Encoding.default_internal = nil
+
+ s = "こんにちは!"
+ # If no encoding is specified, use UTF-8
+ assert_equal Encoding::UTF_8, Psych.dump(s).encoding
+ assert_equal s, Psych.load(Psych.dump(s))
+ ensure
+ Encoding.default_external = ext_before
+ Encoding.default_internal = int_before
+ end
+
def test_start_mapping
foo = 'foo'
bar = 'バー'