fix for api calls with square bracket filenames

This commit is contained in:
Kyle Drake 2024-03-04 16:38:47 -06:00
parent 3087e39b57
commit e7e5121700
3 changed files with 30 additions and 7 deletions

View file

@ -308,6 +308,15 @@ describe 'api' do
_(site_file_exists?('test.jpg')).must_equal true
end
it 'succeeds with square bracket in filename' do
create_site
@site.generate_api_key!
header 'Authorization', "Bearer #{@site.api_key}"
post '/api/upload', 'te[s]t.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
_(res[:result]).must_equal 'success'
_(site_file_exists?('te[s]t.jpg')).must_equal true
end
it 'succeeds with valid user session' do
create_site
post '/api/upload',

View file

@ -53,7 +53,6 @@ describe 'site_files' do
_(PurgeCacheWorker.jobs.collect {|p| p['args'].last}.sort).must_equal ["/notindex", "/notindex2"]
end
it 'renames in same path' do
uploaded_file = Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
upload 'files[]' => uploaded_file
@ -433,6 +432,13 @@ describe 'site_files' do
_(@site.site_changed).must_equal false
end
it 'works with square bracket filename' do
uploaded_file = Rack::Test::UploadedFile.new('./tests/files/te[s]t.jpg', 'image/jpeg')
upload 'files[]' => uploaded_file
_(last_response.body).must_match /successfully uploaded/i
_(File.exists?(@site.files_path('te[s]t.jpg'))).must_equal true
end
it 'sets site changed to false if index is empty' do
uploaded_file = Rack::Test::UploadedFile.new('./tests/files/blankindex/index.html', 'text/html')
upload 'files[]' => uploaded_file