Permalink
Browse files

* ext/psych/lib/psych/nodes/node.rb: default `to_yaml` encoding to be

  UTF-8.
* test/psych/test_encoding.rb: test yaml dump encoding.
  • Loading branch information...
1 parent 95fc907 commit fe65329ce9ece399d61dadf1610e342ff456654e @tenderlove tenderlove committed Aug 24, 2011
Showing with 23 additions and 1 deletion.
  1. +6 −0 CHANGELOG.rdoc
  2. +1 −1 lib/psych/nodes/node.rb
  3. +16 −0 test/psych/test_encoding.rb
View
@@ -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
@@ -41,7 +41,7 @@ def to_ruby
#
# 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
@@ -40,6 +40,22 @@ def test_emit_alias
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 = 'バー'

0 comments on commit fe65329

Please sign in to comment.