diff --git a/git_cl.py b/git_cl.py index 3540382b0..22c158532 100755 --- a/git_cl.py +++ b/git_cl.py @@ -881,10 +881,10 @@ def ParseIssueNumberArgument(arg): if arg.isdigit(): return _ParsedIssueNumberArgument(issue=int(arg)) - if not arg.startswith('http'): - return fail_result url = gclient_utils.UpgradeToHttps(arg) + if not url.startswith('http'): + return fail_result for gerrit_url, short_url in _KNOWN_GERRIT_TO_SHORT_URLS.items(): if url.startswith(short_url): url = gerrit_url + url[len(short_url):] @@ -895,6 +895,11 @@ def ParseIssueNumberArgument(arg): except ValueError: return fail_result + # If "https://" was automatically added, fail if `arg` looks unlikely to be a + # URL. + if not arg.startswith('http') and '.' not in parsed_url.netloc: + return fail_result + # Gerrit's new UI is https://domain/c/project/+/[/[patchset]] # But old GWT UI is https://domain/#/c/project/+/[/[patchset]] # Short urls like https://domain/ can be used, but don't allow diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py index a88c5e3a2..7be4ebc3c 100755 --- a/tests/git_cl_test.py +++ b/tests/git_cl_test.py @@ -476,6 +476,11 @@ class TestParseIssueURL(unittest.TestCase): self._test('https://crrev.com/c/2151934', 2151934, None, 'chromium-review.googlesource.com') + def test_missing_scheme(self): + self._test('codereview.source.com/123', 123, None, 'codereview.source.com') + self._test('crrev.com/c/2151934', 2151934, None, + 'chromium-review.googlesource.com') + class GitCookiesCheckerTest(unittest.TestCase): def setUp(self):