Skip to content

Commit 60a6d74

Browse files
committed
Use safe_load and safe_load_file for .rdoc_options
1 parent 32ff6ba commit 60a6d74

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

lib/rdoc/rdoc.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,12 @@ def load_options
162162
RDoc.load_yaml
163163

164164
begin
165-
options = YAML.load_file '.rdoc_options'
165+
options = YAML.safe_load_file '.rdoc_options', permitted_classes: [RDoc::Options, Symbol]
166166
rescue Psych::SyntaxError
167+
raise RDoc::Error, "#{options_file} is not a valid rdoc options file"
167168
end
168169

169-
return RDoc::Options.new if options == false # Allow empty file.
170+
return RDoc::Options.new unless options # Allow empty file.
170171

171172
raise RDoc::Error, "#{options_file} is not a valid rdoc options file" unless
172173
RDoc::Options === options or Hash === options

test/rdoc/test_rdoc_options.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def test_init_with_encoding
145145

146146
@options.encoding = Encoding::IBM437
147147

148-
options = YAML.load YAML.dump @options
148+
options = YAML.safe_load(YAML.dump(@options), permitted_classes: [RDoc::Options, Symbol])
149149

150150
assert_equal Encoding::IBM437, options.encoding
151151
end
@@ -161,7 +161,7 @@ def test_init_with_trim_paths
161161
- /etc
162162
YAML
163163

164-
options = YAML.load yaml
164+
options = YAML.safe_load(yaml, permitted_classes: [RDoc::Options, Symbol])
165165

166166
assert_empty options.rdoc_include
167167
assert_empty options.static_path
@@ -749,7 +749,7 @@ def test_write_options
749749

750750
assert File.exist? '.rdoc_options'
751751

752-
assert_equal @options, YAML.load(File.read('.rdoc_options'))
752+
assert_equal @options, YAML.safe_load(File.read('.rdoc_options'), permitted_classes: [RDoc::Options, Symbol])
753753
end
754754
end
755755

0 commit comments

Comments
 (0)