def sanitize_filename(value)
# get only the filename, not the whole path
- just_filename = value.gsub(/^.*(\\|\/)/, '')
+ just_filename = value.gsub(/\A.*(\\|\/)/m, '')
# Finally, replace invalid characters with underscore
- @filename = just_filename.gsub(/[\/\?\%\*\:\|\"\'<>]+/, '_')
+ @filename = just_filename.gsub(/[\/\?\%\*\:\|\"\'<>\n\r]+/, '_')
end
# Returns the subdirectory in which the attachment will be saved
assert_nil Attachment.new.container
end
+ def test_filename_should_remove_eols
+ assert_equal "line_feed", Attachment.new(:filename => "line\nfeed").filename
+ assert_equal "line_feed", Attachment.new(:filename => "some\npath/line\nfeed").filename
+ assert_equal "carriage_return", Attachment.new(:filename => "carriage\rreturn").filename
+ assert_equal "carriage_return", Attachment.new(:filename => "some\rpath/carriage\rreturn").filename
+ end
+
def test_create
a = Attachment.new(:container => Issue.find(1),
:file => uploaded_test_file("testfile.txt", "text/plain"),