https://www.redmine.org/https://www.redmine.org/favicon.ico?16793021292013-09-04T07:00:53ZRedmineRedmine - Defect #14819: Newlines in attachment filename causes crashhttps://www.redmine.org/issues/14819?journal_id=515762013-09-04T07:00:53ZEtienne Massip
<ul><li><strong>Category</strong> set to <i>Attachments</i></li><li><strong>Target version</strong> set to <i>Candidate for next major release</i></li></ul> Redmine - Defect #14819: Newlines in attachment filename causes crashhttps://www.redmine.org/issues/14819?journal_id=516912013-09-10T17:22:35ZJean-Philippe Langjp_lang@yahoo.fr
<ul></ul><p>The handling of filenames with new lines seems broken anyway. Shouldn't we remove new lines from filenames instead or in addition to this patch?</p> Redmine - Defect #14819: Newlines in attachment filename causes crashhttps://www.redmine.org/issues/14819?journal_id=517022013-09-11T11:54:25ZFelix Schäfer
<ul></ul><p>I wouldn't mind removing them, but that solves the problem only for new uploads. Existing uploads could be handled either by taking care of the routes as above, or by having a migration to normalize existing filenames of the DB.</p> Redmine - Defect #14819: Newlines in attachment filename causes crashhttps://www.redmine.org/issues/14819?journal_id=517062013-09-11T19:38:20ZJean-Philippe Langjp_lang@yahoo.fr
<ul></ul><p>I'd prefer the migration:</p>
<pre>
Index: db/migrate/20130911193200_remove_eols_from_attachments_filename.rb
===================================================================
--- db/migrate/20130911193200_remove_eols_from_attachments_filename.rb (revision 0)
+++ db/migrate/20130911193200_remove_eols_from_attachments_filename.rb (revision 0)
@@ -0,0 +1,12 @@
+class RemoveEolsFromAttachmentsFilename < ActiveRecord::Migration
+ def up
+ Attachment.where("filename like ? or filename like ?", "%\r%", "%\n%").each do |attachment|
+ filename = attachment.filename.to_s.tr("\r\n", "_")
+ Attachment.where(:id => attachment.id).update_all(:filename => filename)
+ end
+ end
+
+ def down
+ # nop
+ end
+end
</pre>
<p>If it works for you, I'll commit this fix.</p> Redmine - Defect #14819: Newlines in attachment filename causes crashhttps://www.redmine.org/issues/14819?journal_id=517072013-09-11T19:43:45ZFelix Schäfer
<ul></ul><p>Try <code>attachment.update_column(:filename, filename)</code>, other than that it should work.</p>
<p>The fix in itself is good for us, we don't care wether it's solved one way or the other :-) Thanks!</p> Redmine - Defect #14819: Newlines in attachment filename causes crashhttps://www.redmine.org/issues/14819?journal_id=517082013-09-11T21:43:04ZJean-Philippe Langjp_lang@yahoo.fr
<ul><li><strong>Status</strong> changed from <i>New</i> to <i>Closed</i></li><li><strong>Assignee</strong> set to <i>Jean-Philippe Lang</i></li><li><strong>Target version</strong> changed from <i>Candidate for next major release</i> to <i>2.4.0</i></li><li><strong>Resolution</strong> set to <i>Fixed</i></li></ul><p>Migration committed, thanks for the feedback.</p>
<p>About <code>#update_column</code>: I prefer to stick with raw updates in migrations. <code>#update_column</code> does the raw update in the same way and runs some code to reflect the change in the instance attributes. This is neither usefull nor desirable in this migration.</p>