catch dir too long

This commit is contained in:
Kyle Drake 2025-04-15 15:35:17 -05:00
parent f4fcf94b1a
commit 3ccb4ace37
3 changed files with 17 additions and 7 deletions

View file

@ -843,6 +843,10 @@ class Site < Sequel::Model
path = scrubbed_path path path = scrubbed_path path
relative_path = files_path path relative_path = files_path path
if SiteFile.path_too_long?(relative_path)
return 'Directory path is too long.'
end
if Dir.exist?(relative_path) || File.exist?(relative_path) if Dir.exist?(relative_path) || File.exist?(relative_path)
return 'Directory (or file) already exists.' return 'Directory (or file) already exists.'
end end

View file

@ -520,13 +520,6 @@ describe 'site_files' do
_(@site.reload.changed_count).must_equal 2 _(@site.reload.changed_count).must_equal 2
end end
describe 'directory create' do
it 'scrubs ../ from directory' do
@site.create_directory '../../test'
_(@site.site_files.select {|site_file| site_file.path =~ /\.\./}.length).must_equal 0
end
end
describe 'classification' do describe 'classification' do
before do before do
puts "TODO FINISH CLASSIFIER" puts "TODO FINISH CLASSIFIER"

View file

@ -51,6 +51,19 @@ describe Site do
_(site.site_files_dataset.count).must_equal site_file_count+1 _(site.site_files_dataset.count).must_equal site_file_count+1
end end
end end
it 'scrubs ../ from directory' do
site = Fabricate :site
site.create_directory '../../test'
_(site.site_files.select {|site_file| site_file.path =~ /\.\./}.length).must_equal 0
end
it 'blocks long directory create' do
site = Fabricate :site
long_path_string = 'a' * (SiteFile::FILE_PATH_CHARACTER_LIMIT + 1)
res = site.create_directory long_path_string
_(res).must_equal 'Directory path is too long.'
end
end end
describe 'custom_max_space' do describe 'custom_max_space' do