Skip to content

Commit

Permalink
Gracefully deal with YAML::PrivateType objects in Marshal'd gemspecs
Browse files Browse the repository at this point in the history
  • Loading branch information
evanphx authored and ferrous26 committed Mar 22, 2012
1 parent d69a5aa commit 23de077
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/rubygems.rb
Expand Up @@ -671,6 +671,7 @@ def self.load_yaml
YAML::ENGINE.yamler = "psych"
end

require 'rubygems/psych_additions'
require 'rubygems/psych_tree'
end
end
Expand Down
9 changes: 9 additions & 0 deletions lib/rubygems/psych_additions.rb
@@ -0,0 +1,9 @@
# This exists just to satify bugs in marshal'd gemspecs that
# contain a reference to YAML::PrivateType. We prune these out
# in Specification._load, but if we don't have the constant, Marshal
# blows up.

module Psych
class PrivateType
end
end
5 changes: 5 additions & 0 deletions lib/rubygems/specification.rb
Expand Up @@ -666,6 +666,11 @@ def self._load(str)
raise TypeError, "invalid Gem::Specification format #{array.inspect}"
end

# Cleanup any YAML::PrivateType. They only show up for an old bug
# where nil => null, so just convert them to nil based on the type.

array.map! { |e| e.kind_of?(YAML::PrivateType) ? nil : e }

spec.instance_variable_set :@rubygems_version, array[0]
# spec version
spec.instance_variable_set :@name, array[2]
Expand Down

0 comments on commit 23de077

Please sign in to comment.