dont allow directories to end with .htm or .html. Breaks the dashboard UI, also breaks the cdn

This commit is contained in:
Kyle Drake 2024-03-13 16:57:54 -05:00
parent 9dbec11353
commit 88ad085ac8
2 changed files with 15 additions and 1 deletions

View file

@ -81,7 +81,12 @@ class SiteFile < Sequel::Model
return false, "#{is_directory ? 'directory' : 'file'} already exists"
end
unless is_directory
if is_directory
if new_path.match(/\.html?$/)
return false, 'directory name cannot end with .htm or .html'
end
else # a file
mime_type = Magic.guess_file_mime_type site.files_path(self.path)
extname = File.extname new_path

View file

@ -111,6 +111,15 @@ describe 'site_files' do
# No purge cache is executed because the directory is empty
end
it 'fails for directory name ending in .htm or .html' do
@site.create_directory 'dirone'
dirone = @site.site_files_dataset.where(path: 'dirone').first
res = dirone.rename('dasharezone.html')
_(res).must_equal [false, 'directory name cannot end with .htm or .html']
res = dirone.rename('dasharezone.htm')
_(res).must_equal [false, 'directory name cannot end with .htm or .html']
end
it 'wont set an empty directory' do
@site.create_directory 'dirone'
_(@site.site_files.select {|sf| sf.path == 'dirone'}.length).must_equal 1