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>
diff --git a/git_footers.py b/git_footers.py
index a973a11..9ce733d 100755
--- a/git_footers.py
+++ b/git_footers.py
@@ -146,8 +146,15 @@
   top_lines, footer_lines, _ = split_footers(message)
   if not footer_lines:
     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)