diff --git a/git_footers.py b/git_footers.py index 3f12d1735..92c7dab42 100755 --- a/git_footers.py +++ b/git_footers.py @@ -15,6 +15,7 @@ import git_common as git FOOTER_PATTERN = re.compile(r'^\s*([\w-]+): *(.*)$') CHROME_COMMIT_POSITION_PATTERN = re.compile(r'^([\w/\-\.]+)@{#(\d+)}$') +FOOTER_KEY_BLACKLIST = set(['http', 'https']) def normalize_name(header): @@ -24,10 +25,9 @@ def normalize_name(header): def parse_footer(line): """Returns footer's (key, value) if footer is valid, else None.""" match = FOOTER_PATTERN.match(line) - if match: + if match and match.group(1) not in FOOTER_KEY_BLACKLIST: return (match.group(1), match.group(2)) - else: - return None + return None def parse_footers(message): diff --git a/tests/git_footers_test.py b/tests/git_footers_test.py index 5aa3734df..b89adbcaa 100755 --- a/tests/git_footers_test.py +++ b/tests/git_footers_test.py @@ -89,6 +89,24 @@ My commit message is my best friend. It is my life. I must master it. 'For': ['example'], 'And-Only-Valid': ['footers taken']}) + def testAvoidingURLs(self): + message = ('Someone accidentally put a URL in the footers.\n' + '\n' + 'Followed: by\n' + 'http://domain.tld\n' + 'Some: footers') + self.assertEqual(git_footers.split_footers(message), + (['Someone accidentally put a URL in the footers.', + ''], + ['Followed: by', + 'http://domain.tld', + 'Some: footers'], + [('Followed', 'by'), + ('Some', 'footers')])) + self.assertEqual(git_footers.parse_footers(message), + {'Followed': ['by'], + 'Some': ['footers']}) + def testGetFooterChangeId(self): msg = '\n'.join(['whatever', '',