mirror of
https://github.com/neocities/neocities.git
synced 2025-08-11 11:59:22 +02:00
scrub carriage return garbage
This commit is contained in:
parent
249ea7a2d0
commit
26aa62fcae
2 changed files with 24 additions and 1 deletions
|
@ -1165,7 +1165,14 @@ class Site < Sequel::Model
|
||||||
clean << part if part != '..'
|
clean << part if part != '..'
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
def current_files_path(path='')
|
def current_files_path(path='')
|
||||||
|
|
|
@ -106,6 +106,22 @@ describe 'site_files' do
|
||||||
res = @site.site_files.select {|sf| sf.path == 'index.html'}.first.rename('notindex.html')
|
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']
|
res.must_equal [false, 'cannot rename or move root index.html']
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe 'delete' do
|
describe 'delete' do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue