2011-03-10 Caio Marcelo de Oliveira Filho <caio.oliveira@openbossa.org>
[WebKit-https.git] / Websites / bugs.webkit.org / PrettyPatch / PrettyPatch.rb
index 8f42ac2f8ed1a4d66483e2c0203c16f1fa5d9ebb..2eaf3c14c78a2981a06686b86d7d563a77b41b16 100644 (file)
@@ -65,7 +65,7 @@ private
 
     START_OF_BINARY_DATA_FORMAT = /^[0-9a-zA-Z\+\/=]{20,}/ # Assume 20 chars without a space is base64 binary data.
 
-    START_OF_SECTION_FORMAT = /^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@\s*(.*)/
+    START_OF_SECTION_FORMAT = /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@\s*(.*)/
 
     START_OF_EXTENT_STRING = "%c" % 0
     END_OF_EXTENT_STRING = "%c" % 1
@@ -670,7 +670,14 @@ END
             lines.length >= 1 or raise "DiffSection.parse only received %d lines" % lines.length
 
             matches = START_OF_SECTION_FORMAT.match(lines[0])
-            from, to = [matches[1].to_i, matches[2].to_i] unless matches.nil?
+
+            if matches
+                from, to = [matches[1].to_i, matches[3].to_i]
+                if matches[2] and matches[4]
+                    from_end = from + matches[2].to_i
+                    to_end = to + matches[4].to_i
+                end
+            end
 
             @blocks = []
             diff_block = nil
@@ -710,6 +717,8 @@ END
                     from += 1 unless from.nil?
                     to += 1 unless to.nil?
                 end
+
+                break if from_end and to_end and from == from_end and to == to_end
             end
 
             changes = [ [ [], [] ] ]
@@ -753,7 +762,7 @@ END
                 end
             end
 
-            @blocks.unshift(ContextLine.new(matches[3])) unless matches.nil? || matches[3].empty?
+            @blocks.unshift(ContextLine.new(matches[5])) unless matches.nil? || matches[5].empty?
         end
 
         def to_html