Skip to content

Commit 83571ba

Browse files
hsbtmatzbot
authored andcommitted
[ruby/rubygems] Load rdoc_options and requirements from YAML
ruby/rubygems@20153ebc78
1 parent ca215b7 commit 83571ba

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

lib/rubygems/specification.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2190,10 +2190,13 @@ def raise_if_conflicts # :nodoc:
21902190
end
21912191

21922192
##
2193-
# Sets rdoc_options to +value+, ensuring it is an array.
2193+
# Sets rdoc_options to +value+, ensuring it is a flat array of strings.
2194+
# Handles malformed gemspecs where rdoc_options may be a Hash or contain Hashes.
21942195

21952196
def rdoc_options=(options)
2196-
@rdoc_options = Array options
2197+
@rdoc_options = Array(options).flat_map do |opt|
2198+
opt.is_a?(Hash) ? opt.to_a.flatten.map(&:to_s) : opt
2199+
end
21972200
end
21982201

21992202
##
@@ -2553,6 +2556,10 @@ def yaml_initialize(tag, vals) # :nodoc:
25532556
self.date = val
25542557
when "platform"
25552558
self.platform = val
2559+
when "rdoc_options"
2560+
self.rdoc_options = val
2561+
when "requirements"
2562+
self.requirements = val
25562563
else
25572564
instance_variable_set "@#{ivar}", val
25582565
end

test/rubygems/test_gem_safe_yaml.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ def test_rdoc_options_hash_converted_to_array
332332
assert_kind_of Gem::Specification, spec
333333
assert_equal "test-gem", spec.name
334334

335-
assert_kind_of Hash, spec.rdoc_options
335+
assert_equal [], spec.rdoc_options
336336
end
337337

338338
def test_load_returns_nil_for_comment_only_yaml
@@ -1117,7 +1117,7 @@ def test_regression_rdoc_options_normalized_to_array
11171117
YAML
11181118

11191119
spec = Gem::SafeYAML.safe_load(yaml)
1120-
assert_kind_of Hash, spec.rdoc_options
1120+
assert_equal ["--title", "MyGem", "--main", "README"], spec.rdoc_options
11211121
end
11221122

11231123
def test_regression_requirements_field_normalized_to_array
@@ -1133,6 +1133,6 @@ def test_regression_requirements_field_normalized_to_array
11331133
YAML
11341134

11351135
spec = Gem::SafeYAML.safe_load(yaml)
1136-
assert_kind_of Hash, spec.requirements
1136+
assert_equal [["foo", "bar"]], spec.requirements
11371137
end
11381138
end

0 commit comments

Comments
 (0)