Merge pull request #3713 from fw42/fix_marshal_bugs
Merge pull request 3713
This commit is contained in:
commit
f6b34f74a9
|
@ -130,7 +130,7 @@ module Jekyll
|
||||||
#
|
#
|
||||||
# Returns nothing.
|
# Returns nothing.
|
||||||
def write_metadata
|
def write_metadata
|
||||||
File.open(metadata_file, 'w') do |f|
|
File.open(metadata_file, 'wb') do |f|
|
||||||
f.write(Marshal.dump(metadata))
|
f.write(Marshal.dump(metadata))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -164,6 +164,9 @@ module Jekyll
|
||||||
Marshal.load(content)
|
Marshal.load(content)
|
||||||
rescue TypeError
|
rescue TypeError
|
||||||
SafeYAML.load(content)
|
SafeYAML.load(content)
|
||||||
|
rescue ArgumentError => e
|
||||||
|
Jekyll.logger.warn("Failed to load #{metadata_file}: #{e}")
|
||||||
|
{}
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
{}
|
{}
|
||||||
|
|
|
@ -144,6 +144,16 @@ class TestRegenerator < JekyllUnitTest
|
||||||
assert_equal File.mtime(@path), @regenerator.metadata[@path]["mtime"]
|
assert_equal File.mtime(@path), @regenerator.metadata[@path]["mtime"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "not crash when reading corrupted marshal file" do
|
||||||
|
metadata_file = source_dir(".jekyll-metadata")
|
||||||
|
File.open(metadata_file, "w") do |file|
|
||||||
|
file.puts Marshal.dump({ foo: 'bar' })[0,5]
|
||||||
|
end
|
||||||
|
|
||||||
|
@regenerator = Regenerator.new(@site)
|
||||||
|
assert_equal({}, @regenerator.metadata)
|
||||||
|
end
|
||||||
|
|
||||||
# Methods
|
# Methods
|
||||||
|
|
||||||
should "be able to add a path to the metadata" do
|
should "be able to add a path to the metadata" do
|
||||||
|
|
Loading…
Reference in New Issue