scrub carriage return garbage

This commit is contained in:
Kyle Drake 2019-02-13 22:45:28 -08:00
parent 249ea7a2d0
commit 26aa62fcae
2 changed files with 24 additions and 1 deletions

View file

@ -1165,7 +1165,14 @@ class Site < Sequel::Model
clean << part if part != '..'
end
clean.join '/'
clean_path = clean.join '/'
# Scrub carriage garbage (everything below 32 bytes.. http://www.asciitable.com/)
clean_path.each_codepoint do |c|
raise ArgumentError, 'invalid character for filename' if c < 32
end
clean_path
end
def current_files_path(path='')

View file

@ -106,6 +106,22 @@ describe 'site_files' do
res = @site.site_files.select {|sf| sf.path == 'index.html'}.first.rename('notindex.html')
res.must_equal [false, 'cannot rename or move root index.html']
end
it 'works with unicode characters' do
uploaded_file = Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
upload 'files[]' => uploaded_file
@site.site_files.last.rename("HELL💩؋.jpg")
@site.site_files.last.path.must_equal "HELL💩؋.jpg"
end
it 'scrubs weird carriage return shit characters' do
uploaded_file = Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
upload 'files[]' => uploaded_file
proc {
@site.site_files.last.rename("\r\n\t.jpg")
}.must_raise ArgumentError
@site.site_files.last.path.must_equal "test.jpg"
end
end
describe 'delete' do