Merge pull request #3713 from fw42/fix_marshal_bugs

Merge pull request 3713
This commit is contained in:
Alfred Xing 2015-05-19 22:53:04 -07:00
commit f6b34f74a9
2 changed files with 14 additions and 1 deletions

View File

@ -130,7 +130,7 @@ module Jekyll
#
# Returns nothing.
def write_metadata
File.open(metadata_file, 'w') do |f|
File.open(metadata_file, 'wb') do |f|
f.write(Marshal.dump(metadata))
end
end
@ -164,6 +164,9 @@ module Jekyll
Marshal.load(content)
rescue TypeError
SafeYAML.load(content)
rescue ArgumentError => e
Jekyll.logger.warn("Failed to load #{metadata_file}: #{e}")
{}
end
else
{}

View File

@ -144,6 +144,16 @@ class TestRegenerator < JekyllUnitTest
assert_equal File.mtime(@path), @regenerator.metadata[@path]["mtime"]
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
should "be able to add a path to the metadata" do