Skip to content

Commit cc86612

Browse files
authored
Merge pull request #9391 from jhawthorn/fix_safe_yaml_load
Make SafeYAML.load an alias of safe_load
2 parents f39a8c6 + d8d927f commit cc86612

4 files changed

Lines changed: 5 additions & 22 deletions

File tree

lib/rubygems/commands/owner_command.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def show_owners(name)
7575
end
7676

7777
with_response response do |resp|
78-
owners = Gem::SafeYAML.load clean_text(resp.body)
78+
owners = Gem::SafeYAML.safe_load clean_text(resp.body)
7979

8080
say "Owners for gem: #{name}"
8181
owners.each do |owner|

lib/rubygems/safe_yaml.rb

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,8 @@ def self.safe_load(input)
4848
end
4949
end
5050

51-
def self.load(input)
52-
if Gem.use_psych?
53-
if ::Psych.respond_to?(:unsafe_load)
54-
::Psych.unsafe_load(input)
55-
else
56-
::Psych.load(input)
57-
end
58-
else
59-
Gem::YAMLSerializer.load(
60-
input,
61-
permitted_classes: PERMITTED_CLASSES,
62-
permitted_symbols: PERMITTED_SYMBOLS,
63-
aliases: aliases_enabled?
64-
)
65-
end
51+
class << self
52+
alias_method :load, :safe_load
6653
end
6754
end
6855
end

test/rubygems/helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -735,10 +735,10 @@ def write_dummy_extconf(gem_name)
735735
end
736736

737737
##
738-
# Load a YAML string, the psych 3 way
738+
# Load a YAML string using the safe loader with gem-spec permitted classes.
739739

740740
def load_yaml(yaml)
741-
Gem::SafeYAML.load(yaml)
741+
Gem::SafeYAML.safe_load(yaml)
742742
end
743743

744744
##

test/rubygems/test_gem_commands_owner_command.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ def test_show_owners
5757
def test_show_owners_dont_load_objects
5858
Gem.load_yaml
5959

60-
# Gem::SafeYAML.load uses Psych.unsafe_load when Psych is enabled,
61-
# which does not restrict classes. Only YAMLSerializer restricts object tags.
62-
pend "Gem::SafeYAML.load uses Psych.unsafe_load which does not restrict classes" if Gem.use_psych?
63-
6460
response = <<EOF
6561
---
6662
- email: !ruby/object:Object {}

0 commit comments

Comments
 (0)