mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
prevent creation of empty path with rename
This commit is contained in:
parent
671b29bc9f
commit
75f225fd88
2 changed files with 15 additions and 0 deletions
|
@ -44,6 +44,10 @@ class SiteFile < Sequel::Model
|
||||||
current_path = self.path
|
current_path = self.path
|
||||||
new_path = site.scrubbed_path new_path
|
new_path = site.scrubbed_path new_path
|
||||||
|
|
||||||
|
if new_path == ''
|
||||||
|
return false, 'cannot rename to empty path'
|
||||||
|
end
|
||||||
|
|
||||||
if current_path == 'index.html'
|
if current_path == 'index.html'
|
||||||
return false, 'cannot rename or move root index.html'
|
return false, 'cannot rename or move root index.html'
|
||||||
end
|
end
|
||||||
|
|
|
@ -81,6 +81,17 @@ describe 'site_files' do
|
||||||
PurgeCacheWorker.jobs.last['args'].last.must_equal 'dasharezone'
|
PurgeCacheWorker.jobs.last['args'].last.must_equal 'dasharezone'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'wont set an empty directory' do
|
||||||
|
@site.create_directory 'dirone'
|
||||||
|
@site.site_files.select {|sf| sf.path == 'dirone'}.length.must_equal 1
|
||||||
|
|
||||||
|
dirone = @site.site_files_dataset.where(path: 'dirone').first
|
||||||
|
res = dirone.rename('')
|
||||||
|
@site.site_files_dataset.where(path: '').count.must_equal 0
|
||||||
|
res.must_equal [false, 'cannot rename to empty path']
|
||||||
|
@site.site_files_dataset.where(path: '').count.wont_equal 1
|
||||||
|
end
|
||||||
|
|
||||||
it 'changes path of files and dirs within directory when changed' do
|
it 'changes path of files and dirs within directory when changed' do
|
||||||
upload(
|
upload(
|
||||||
'dir' => 'test',
|
'dir' => 'test',
|
||||||
|
|
Loading…
Add table
Reference in a new issue