Skip to content

Commit

Permalink
Merge RDoc-6.3.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
hsbt committed Apr 15, 2024
1 parent 33bf1fc commit 6931347
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 25 deletions.
5 changes: 3 additions & 2 deletions lib/rdoc/rdoc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,12 @@ def load_options
RDoc.load_yaml

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

return RDoc::Options.new if options == false # Allow empty file.
return RDoc::Options.new unless options # Allow empty file.

raise RDoc::Error, "#{options_file} is not a valid rdoc options file" unless
RDoc::Options === options or Hash === options
Expand Down
45 changes: 26 additions & 19 deletions lib/rdoc/store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -556,9 +556,7 @@ def load_all
def load_cache
#orig_enc = @encoding

File.open cache_path, 'rb' do |io|
@cache = Marshal.load io.read
end
@cache = marshal_load(cache_path)

load_enc = @cache[:encoding]

Expand Down Expand Up @@ -615,9 +613,7 @@ def load_class klass_name
def load_class_data klass_name
file = class_file klass_name

File.open file, 'rb' do |io|
Marshal.load io.read
end
marshal_load(file)
rescue Errno::ENOENT => e
error = MissingFileError.new(self, file, klass_name)
error.set_backtrace e.backtrace
Expand All @@ -630,14 +626,10 @@ def load_class_data klass_name
def load_method klass_name, method_name
file = method_file klass_name, method_name

File.open file, 'rb' do |io|
obj = Marshal.load io.read
obj.store = self
obj.parent =
find_class_or_module(klass_name) || load_class(klass_name) unless
obj.parent
obj
end
obj = marshal_load(file)
obj.store = self
obj.parent ||= find_class_or_module(klass_name) || load_class(klass_name)
obj
rescue Errno::ENOENT => e
error = MissingFileError.new(self, file, klass_name + method_name)
error.set_backtrace e.backtrace
Expand All @@ -650,11 +642,9 @@ def load_method klass_name, method_name
def load_page page_name
file = page_file page_name

File.open file, 'rb' do |io|
obj = Marshal.load io.read
obj.store = self
obj
end
obj = marshal_load(file)
obj.store = self
obj
rescue Errno::ENOENT => e
error = MissingFileError.new(self, file, page_name)
error.set_backtrace e.backtrace
Expand Down Expand Up @@ -976,4 +966,21 @@ def unique_modules
@unique_modules
end

private
def marshal_load(file)
File.open(file, 'rb') {|io| Marshal.load(io, MarshalFilter)}
end

MarshalFilter = proc do |obj|
case obj
when true, false, nil, Array, Class, Encoding, Hash, Integer, String, Symbol, RDoc::Text
else
unless obj.class.name.start_with?("RDoc::")
raise TypeError, "not permitted class: #{obj.class.name}"
end
end
obj
end
private_constant :MarshalFilter

end
2 changes: 1 addition & 1 deletion lib/rdoc/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module RDoc
##
# RDoc version you are using

VERSION = '6.3.3'
VERSION = '6.3.4.1'

end
6 changes: 3 additions & 3 deletions test/rdoc/test_rdoc_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def test_init_with_encoding

@options.encoding = Encoding::IBM437

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

assert_equal Encoding::IBM437, options.encoding
end
Expand All @@ -161,7 +161,7 @@ def test_init_with_trim_paths
- /etc
YAML

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

assert_empty options.rdoc_include
assert_empty options.static_path
Expand Down Expand Up @@ -749,7 +749,7 @@ def test_write_options

assert File.exist? '.rdoc_options'

assert_equal @options, YAML.load(File.read('.rdoc_options'))
assert_equal @options, YAML.safe_load(File.read('.rdoc_options'), permitted_classes: [RDoc::Options, Symbol])
end
end

Expand Down

0 comments on commit 6931347

Please sign in to comment.