Преглед на файлове

git_footer: be more resilient to malformed footers

Since split_footers became more resilient to malformed
footers and started returning the entire last paragraph,
instead of just the last paragraph iff it was entirely
well-formed, other functions like remove_footer need to
make sure they handle the case where not every line of
the footer paragraph can be parsed.

R=iannucci@chromium.org

Bug: 740601
Change-Id: I75c6c626d96942181f453abeee896ee92d14b20b
Reviewed-on: https://chromium-review.googlesource.com/565779
Reviewed-by: Robbie Iannucci <iannucci@chromium.org>
Commit-Queue: Aaron Gable <agable@chromium.org>
Aaron Gable преди 8 години
родител
ревизия
b08ba6575e
променени са 1 файла, в които са добавени 9 реда и са изтрити 2 реда
  1. 9 2
      git_footers.py

+ 9 - 2
git_footers.py

@@ -146,8 +146,15 @@ def remove_footer(message, key):
   top_lines, footer_lines, _ = split_footers(message)
   top_lines, footer_lines, _ = split_footers(message)
   if not footer_lines:
   if not footer_lines:
     return message
     return message
-  new_footer_lines = [
-      l for l in footer_lines if normalize_name(parse_footer(l)[0]) != key]
+  new_footer_lines = []
+  for line in footer_lines:
+    try:
+      f = normalize_name(parse_footer(line)[0])
+      if f != key:
+        new_footer_lines.append(line)
+    except TypeError:
+      # If the footer doesn't parse (i.e. is malformed), just let it carry over.
+      new_footer_lines.append(line)
   return '\n'.join(top_lines + new_footer_lines)
   return '\n'.join(top_lines + new_footer_lines)