From 3ccb4ace377e24913c8775ab653a1d72a5472bc7 Mon Sep 17 00:00:00 2001 From: Kyle Drake Date: Tue, 15 Apr 2025 15:35:17 -0500 Subject: [PATCH] catch dir too long --- models/site.rb | 4 ++++ tests/site_file_tests.rb | 7 ------- tests/site_tests.rb | 13 +++++++++++++ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/models/site.rb b/models/site.rb index 0bccc7f0..5c00141b 100644 --- a/models/site.rb +++ b/models/site.rb @@ -843,6 +843,10 @@ class Site < Sequel::Model path = scrubbed_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) return 'Directory (or file) already exists.' end diff --git a/tests/site_file_tests.rb b/tests/site_file_tests.rb index 2a7dadfb..a2218edc 100644 --- a/tests/site_file_tests.rb +++ b/tests/site_file_tests.rb @@ -520,13 +520,6 @@ describe 'site_files' do _(@site.reload.changed_count).must_equal 2 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 before do puts "TODO FINISH CLASSIFIER" diff --git a/tests/site_tests.rb b/tests/site_tests.rb index 93cc185b..9cc1cc87 100644 --- a/tests/site_tests.rb +++ b/tests/site_tests.rb @@ -51,6 +51,19 @@ describe Site do _(site.site_files_dataset.count).must_equal site_file_count+1 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 describe 'custom_max_space' do