mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
Fix for deletion with regexp escape chars
This commit is contained in:
parent
01e721adca
commit
68e4424725
2 changed files with 8 additions and 3 deletions
|
@ -9,14 +9,14 @@ class SiteFile < Sequel::Model
|
|||
|
||||
def before_destroy
|
||||
if is_directory
|
||||
site.site_files_dataset.where(path: /^#{path}\//, is_directory: true).all.each do |site_file|
|
||||
site.site_files_dataset.where(path: /^#{Regexp.quote path}\//, is_directory: true).all.each do |site_file|
|
||||
begin
|
||||
site_file.destroy
|
||||
rescue Sequel::NoExistingObject
|
||||
end
|
||||
end
|
||||
|
||||
site.site_files_dataset.where(path: /^#{path}\//, is_directory: false).all.each do |site_file|
|
||||
site.site_files_dataset.where(path: /^#{Regexp.quote path}\//, is_directory: false).all.each do |site_file|
|
||||
site_file.destroy
|
||||
end
|
||||
|
||||
|
@ -50,4 +50,3 @@ class SiteFile < Sequel::Model
|
|||
SiteChangeFile.filter(site_id: site_id, filename: path).delete
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -63,6 +63,12 @@ describe 'site_files' do
|
|||
DeleteCacheOrderWorker.jobs.collect {|j| j['args'].last}.must_equal ['/index.html', '/?surf=1', '/']
|
||||
end
|
||||
|
||||
it 'property deletes directories with regexp special chars in them' do
|
||||
upload 'dir' => '8)', 'files[]' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
delete_file filename: '8)'
|
||||
@site.reload.site_files.select {|f| f.path =~ /#{Regexp.quote '8)'}/}.length.must_equal 0
|
||||
end
|
||||
|
||||
it 'deletes a directory and all files in it' do
|
||||
upload(
|
||||
'dir' => 'test',
|
||||
|
|
Loading…
Add table
Reference in a new issue