Skip to content

Commit

Permalink
Check parameter types in FilterSourceFile() mock
Browse files Browse the repository at this point in the history
Parameters |white_list| and |black_list| in FilterSourceFile()
should be iterables, and it's fairly easy to wrongly pass a string
instead.

This checking caught _CheckCrbugLinksHaveHttps in unit tests.

Bug: 869103
Change-Id: I1cd6d62c3fa2b1500d9d7b6b35794f40e35378af
Reviewed-on: https://chromium-review.googlesource.com/1155379
Commit-Queue: Wei-Yin Chen (陳威尹) <wychen@chromium.org>
Reviewed-by: Dirk Pranke <dpranke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579288}
  • Loading branch information
wychen authored and Commit Bot committed Jul 31, 2018
1 parent 2f54a8a commit b1ce354
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion PRESUBMIT.py
Expand Up @@ -3278,7 +3278,7 @@ def _CheckCrbugLinksHaveHttps(input_api, output_api):
"""Checks that crbug(.com) links are correctly prefixed by https://,
unless they come in the accepted form TODO(crbug.com/...)
"""
white_list = r'.+%s' % _IMPLEMENTATION_EXTENSIONS
white_list = (r'.+%s' % _IMPLEMENTATION_EXTENSIONS, )
black_list = (_EXCLUDED_PATHS + _TEST_CODE_EXCLUDED_PATHS)
sources = lambda f: input_api.FilterSourceFile(
f, white_list=white_list, black_list=black_list)
Expand Down
4 changes: 4 additions & 0 deletions PRESUBMIT_test_mocks.py
Expand Up @@ -94,12 +94,16 @@ def FilterSourceFile(self, file, white_list=(), black_list=()):
local_path = file.LocalPath()
found_in_white_list = not white_list
if white_list:
if type(white_list) is str:
raise TypeError('white_list should be an iterable of strings')
for pattern in white_list:
compiled_pattern = re.compile(pattern)
if compiled_pattern.search(local_path):
found_in_white_list = True
break
if black_list:
if type(black_list) is str:
raise TypeError('black_list should be an iterable of strings')
for pattern in black_list:
compiled_pattern = re.compile(pattern)
if compiled_pattern.search(local_path):
Expand Down

0 comments on commit b1ce354

Please sign in to comment.