]> source.dussan.org Git - redmine.git/commitdiff
Normalize issue description EOLs do prevent false journal details (#8712).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 2 Jul 2011 11:42:46 +0000 (11:42 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 2 Jul 2011 11:42:46 +0000 (11:42 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@6149 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/issue.rb
test/unit/issue_test.rb

index 5fe0d0517b6581a8c52c7e50ce4637bf50f2c833..79c491547be8a3972b241b43b545199f738fccf4 100644 (file)
@@ -227,6 +227,13 @@ class Issue < ActiveRecord::Base
     @custom_field_values = nil
     result
   end
+  
+  def description=(arg)
+    if arg.is_a?(String)
+      arg = arg.gsub(/(\r\n|\n|\r)/, "\r\n")
+    end
+    write_attribute(:description, arg)
+  end
 
   # Overrides attributes= so that tracker_id gets assigned first
   def attributes_with_tracker_first=(new_attributes, *args)
index 92f604e52364f1ccea3584f0766b9572aa3818d5..b19ddaa85fb2713dc312ded47fdee651951aabe6 100644 (file)
@@ -738,7 +738,7 @@ class IssueTest < ActiveSupport::TestCase
     IssueCustomField.delete_all
     Issue.update_all("description = NULL", "id=1")
     
-    i = Issue.first
+    i = Issue.find(1)
     i.init_journal(User.find(2))
     i.subject = "blank description"
     i.description = "\r\n"
@@ -749,6 +749,11 @@ class IssueTest < ActiveSupport::TestCase
       end
     end
   end
+  
+  def test_description_eol_should_be_normalized
+    i = Issue.new(:description => "CR \r LF \n CRLF \r\n")
+    assert_equal "CR \r\n LF \r\n CRLF \r\n", i.description
+  end
 
   def test_saving_twice_should_not_duplicate_journal_details
     i = Issue.find(:first)