pre-upload: rewrite tag logic to avoid filter()

We've banned the filter() builtin, so rewrite the logic to avoid it.
This makes the check slightly more strict in that we only allow tags
with the correct case, but that should be fine.

BUG=chromium:982868
TEST=unittests pass

Change-Id: Ia10dff1ac2027b77e435c1d1155cefdf74031b94
Reviewed-on: https://chromium-review.googlesource.com/1729850
Tested-by: Mike Frysinger <vapier@chromium.org>
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Jack Neus <jackneus@google.com>
diff --git a/pre-upload.py b/pre-upload.py
index b8ed460..789e53a 100755
--- a/pre-upload.py
+++ b/pre-upload.py
@@ -645,7 +645,7 @@
   if project.name not in ALLOWLIST:
     return None
 
-  TAGS = (
+  TAGS = {
       'Reviewed-on',
       'Reviewed-by',
       'Signed-off-by',
@@ -659,15 +659,14 @@
       'Suggested-by',
       'Reported-by',
       'Acked-for-chrome-by',
-  )
+  }
 
   # Ignore tags, which could reasonably contain OEM names
   # (e.g. Reviewed-by: foo@oem.corp-partner.google.com).
-  def tag_filter(x):
-    return not any(x.lower().startswith(h.lower()) for h in TAGS)
-
   commit_message = ' '.join(
-      filter(tag_filter, _get_commit_desc(commit).splitlines()))
+      x for x in _get_commit_desc(commit).splitlines()
+      if ':' not in x or x.split(':', 1)[0] not in TAGS)
+
   commit_message = re.sub(r'[\s_-]+', ' ', commit_message)
 
   # Exercise caution when expanding these lists. Adding a name
diff --git a/pre-upload_unittest.py b/pre-upload_unittest.py
index c553651..5fadf24 100755
--- a/pre-upload_unittest.py
+++ b/pre-upload_unittest.py
@@ -1279,6 +1279,9 @@
     self.assertMessageRejected(
         'Asus project\n'
         'Reviewed-by: partner@asus.corp-partner.google.com')
+    self.assertMessageRejected(
+        'my project\n'
+        'Bad-tag: partner@asus.corp-partner.google.com')
 
 
 class CheckCommitMessageStyle(CommitMessageTestCase):