mirror of
https://github.com/jekyll/jekyll.git
synced 2026-01-30 09:18:11 -05:00
Add checks to prevent accidental deletion of the source directory
This commit is contained in:
@@ -70,6 +70,12 @@ module Jekyll
|
||||
def setup
|
||||
require 'classifier' if self.lsi
|
||||
|
||||
# Check that the destination dir isn't the source dir or a directory
|
||||
# parent to the source dir.
|
||||
if self.source =~ /^#{self.dest}/
|
||||
raise FatalException.new "Destination directory cannot be or contain the Source directory."
|
||||
end
|
||||
|
||||
# If safe mode is off, load in any Ruby files under the plugins
|
||||
# directory.
|
||||
unless self.safe
|
||||
|
||||
@@ -166,6 +166,28 @@ class TestSite < Test::Unit::TestCase
|
||||
assert_equal files, @site.filter_entries(files)
|
||||
end
|
||||
|
||||
context 'error handling' do
|
||||
should "raise if destination is included in source" do
|
||||
stub(Jekyll).configuration do
|
||||
Jekyll::DEFAULTS.merge({'source' => source_dir, 'destination' => source_dir})
|
||||
end
|
||||
|
||||
assert_raise Jekyll::FatalException do
|
||||
site = Site.new(Jekyll.configuration)
|
||||
end
|
||||
end
|
||||
|
||||
should "raise if destination is source" do
|
||||
stub(Jekyll).configuration do
|
||||
Jekyll::DEFAULTS.merge({'source' => source_dir, 'destination' => File.join(source_dir, "..")})
|
||||
end
|
||||
|
||||
assert_raise Jekyll::FatalException do
|
||||
site = Site.new(Jekyll.configuration)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with orphaned files in destination' do
|
||||
setup do
|
||||
clear_dest
|
||||
|
||||
Reference in New Issue
Block a user