Permalink
Browse files

Manually backport encoding-aware YAML gemspec

Gem::Specification was not serialized properly with Ruby 1.9

This solves issue #314, which was not fully backported into 1.8 branch.

Since code and test orgnization differs between branches, I've modified
the test to fit 1.8 branch organization.
  • Loading branch information...
1 parent 1e97cce commit a1827da244e275ea55832586edcaf145aeca5fd7 @luislavena luislavena committed Jul 18, 2012
Showing with 12 additions and 0 deletions.
  1. +1 −0 lib/rubygems/specification.rb
  2. +11 −0 test/rubygems/test_gem_specification.rb
@@ -1946,6 +1946,7 @@ def to_yaml(opts = {}) # :nodoc:
ast = builder.tree
io = StringIO.new
+ io.set_encoding Encoding::UTF_8 if Object.const_defined? :Encoding
Psych::Visitors::Emitter.new(io).accept(ast)
@@ -1,3 +1,5 @@
+# coding: UTF-8
+
require 'rubygems/test_case'
require 'stringio'
require 'rubygems/specification'
@@ -1175,6 +1177,15 @@ def test_to_yaml
assert_equal @a1, same_spec
end
+ def test_to_yaml_encoding
+ @a1.description = 'π'
+
+ yaml_str = @a1.to_yaml
+ same_spec = Gem::Specification.from_yaml(yaml_str)
+
+ assert_equal @a1.description, same_spec.description
+ end
+
def test_to_yaml_fancy
@a1.platform = Gem::Platform.local
yaml_str = @a1.to_yaml

0 comments on commit a1827da

Please sign in to comment.