Skip to content

Commit

Permalink
* ext/psych/lib/psych/nodes/node.rb: default to_yaml encoding to be
Browse files Browse the repository at this point in the history
  UTF-8.
* test/psych/test_encoding.rb: test yaml dump encoding.
  • Loading branch information
tenderlove committed Aug 24, 2011
1 parent 95fc907 commit fe65329
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
6 changes: 6 additions & 0 deletions 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
Expand Down
2 changes: 1 addition & 1 deletion lib/psych/nodes/node.rb
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions test/psych/test_encoding.rb
Expand Up @@ -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 = 'バー'
Expand Down

0 comments on commit fe65329

Please sign in to comment.