Skip to content

Commit

Permalink
Restore fix from issue #149 for YAML spec loading. Set proper encodin…
Browse files Browse the repository at this point in the history
…g for Gem::Specification#to_yaml
  • Loading branch information
drbrain committed Jan 11, 2012
1 parent 7a2a100 commit d781b0a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/rubygems/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,11 @@ def load_spec entry # :nodoc:
when 'metadata' then
@spec = Gem::Specification.from_yaml entry.read
when 'metadata.gz' then
Zlib::GzipReader.wrap entry do |gzio|
args = [entry]
args << { :external_encoding => Encoding::UTF_8 } if
Object.const_defined? :Encoding

Zlib::GzipReader.wrap *args do |gzio|
@spec = Gem::Specification.from_yaml gzio.read
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/rubygems/specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2185,6 +2185,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)

Expand Down
14 changes: 14 additions & 0 deletions test/rubygems/test_gem_package.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# coding: UTF-8

require 'rubygems/package/tar_test_case'
require 'rubygems/simple_gem'

Expand All @@ -7,6 +9,7 @@ def setup
super

@spec = quick_gem 'a' do |s|
s.description = 'π'
s.files = %w[lib/code.rb]
end

Expand Down Expand Up @@ -227,6 +230,17 @@ def test_install_location_relative
"#{@destination} is not allowed", e.message)
end

def test_load_spec
entry = StringIO.new Gem.gzip @spec.to_yaml
def entry.full_name() 'metadata.gz' end

package = Gem::Package.new 'nonexistent.gem'

spec = package.load_spec entry

assert_equal @spec, spec
end

def test_verify
package = Gem::Package.new @gem

Expand Down

0 comments on commit d781b0a

Please sign in to comment.