]> source.dussan.org Git - redmine.git/commitdiff
Fixes diff parser for when lines starting with multiple dashes are removed (#4186).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 11 Nov 2009 13:25:53 +0000 (13:25 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 11 Nov 2009 13:25:53 +0000 (13:25 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3028 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/redmine/unified_diff.rb
test/unit/lib/redmine/unified_diff_test.rb

index e66ff217fec979c025e07ddf82e95dc71bbe1152..09fbfcf1a9dd5a6d7cd1eab311ea4467ced6a956 100644 (file)
@@ -27,11 +27,10 @@ module Redmine
       @truncated = false
       diff_table = DiffTable.new(diff_type)
       diff.each do |line|
-        if line =~ /^(---|\+\+\+) (.*)$/
+        unless diff_table.add_line line
           self << diff_table if diff_table.length > 1
           diff_table = DiffTable.new(diff_type)
         end
-        diff_table.add_line line
         lines += 1
         if options[:max_lines] && lines > options[:max_lines]
           @truncated = true
@@ -61,11 +60,11 @@ module Redmine
     end
 
     # Function for add a line of this Diff
+    # Returns false when the diff ends
     def add_line(line)
       unless @parsing
         if line =~ /^(---|\+\+\+) (.*)$/
           @file_name = $2
-          return false
         elsif line =~ /^@@ (\+|\-)(\d+)(,\d+)? (\+|\-)(\d+)(,\d+)? @@/
           @line_num_l = $2.to_i
           @line_num_r = $5.to_i
index 5b26cde25d8d386945ed16e43e4d9f906dd07d35..7193b230a9954c2322d2dc4200f90ce3dcd8f84b 100644 (file)
@@ -33,6 +33,32 @@ class Redmine::UnifiedDiffTest < ActiveSupport::TestCase
     diff = Redmine::UnifiedDiff.new(read_diff_fixture('subversion.diff'), :max_lines => 20)
     assert_equal 2, diff.size
   end
+  
+  def test_line_starting_with_dashes
+    diff = Redmine::UnifiedDiff.new(<<-DIFF
+--- old.txt Wed Nov 11 14:24:58 2009
++++ new.txt Wed Nov 11 14:25:02 2009
+@@ -1,8 +1,4 @@
+-Lines that starts with dashes:
+-
+-------------------------
+--- file.c
+-------------------------
++A line that starts with dashes:
+ and removed.
+@@ -23,4 +19,4 @@
+-Another chunk of change
++Another chunk of changes
+
+DIFF
+    )
+    assert_equal 1, diff.size
+  end
 
   private