Commit d9a6756b authored by Aaron Gable's avatar Aaron Gable Committed by Commit Bot

Blacklist http(s): from being parsed as a git footer

It's unlikely that anyone would ever intend to have a git trailer
whose key is "http", but since URLs are often long, it is rather
likely that someone would put a URL on a line all by itself. When
that happens, don't accidentally interpret it as a footer.

R=iannucci, tandrii

Bug: 766234
Change-Id: I3101119c4e49e20339487618cc1719452b026d90
Reviewed-on: https://chromium-review.googlesource.com/849484
Commit-Queue: Aaron Gable <agable@chromium.org>
Reviewed-by: 's avatarAndrii Shyshkalov <tandrii@chromium.org>
parent ebe839b6
......@@ -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):
......
......@@ -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',
'',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment