mirror of
https://github.com/neocities/neocities.git
synced 2026-05-26 05:34:53 +00:00
site_file: catch for moving directory into itself
This commit is contained in:
@@ -89,6 +89,10 @@ class SiteFile < Sequel::Model
|
||||
return false, 'directory name cannot end with .htm or .html'
|
||||
end
|
||||
|
||||
if new_path.start_with?(current_path + '/')
|
||||
return false, 'cannot move directory into itself'
|
||||
end
|
||||
|
||||
else # a file
|
||||
begin
|
||||
mime_type = Magic.guess_file_mime_type site.files_path(self.path)
|
||||
|
||||
@@ -107,6 +107,20 @@ describe 'site_files' do
|
||||
_(res).must_equal [false, 'directory name cannot end with .htm or .html']
|
||||
end
|
||||
|
||||
it 'fails when trying to move directory into itself' do
|
||||
@site.create_directory 'dir'
|
||||
dir = @site.site_files_dataset.where(path: 'dir').first
|
||||
res = dir.rename('dir/newdir')
|
||||
_(res).must_equal [false, 'cannot move directory into itself']
|
||||
_(@site.site_files_dataset.where(path: 'dir').first).wont_equal nil
|
||||
_(@site.site_files_dataset.where(path: 'dir/newdir').first).must_equal nil
|
||||
|
||||
res = dir.rename('dir/sub/dir')
|
||||
_(res).must_equal [false, 'cannot move directory into itself']
|
||||
_(@site.site_files_dataset.where(path: 'dir').first).wont_equal nil
|
||||
_(@site.site_files_dataset.where(path: 'dir/sub/dir').first).must_equal nil
|
||||
end
|
||||
|
||||
it 'wont set an empty directory' do
|
||||
@site.create_directory 'dirone'
|
||||
_(@site.site_files.select {|sf| sf.path == 'dirone'}.length).must_equal 1
|
||||
|
||||
Reference in New Issue
Block a user