manifest_xml: do not allow / before : in scp-like syntax

Since git doesn't treat these as ssh:// URIs, we shouldn't either.

Bug: https://g-issues.gerritcodereview.com/issues/40010331
Change-Id: I001f49be30395187cac447d09cb5a6c29e95768b
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/398517
Tested-by: Mike Frysinger <vapier@google.com>
Reviewed-by: Jason Chang <jasonnc@google.com>
Commit-Queue: Mike Frysinger <vapier@google.com>
This commit is contained in:
Mike Frysinger 2023-12-18 16:31:11 -05:00 committed by LUCI
parent 172c58398b
commit 48e4137eba
2 changed files with 12 additions and 1 deletions

View File

@ -134,7 +134,7 @@ def normalize_url(url: str) -> str:
parsed_url = urllib.parse.urlparse(url)
# This matches patterns like "git@github.com:foo/bar".
scp_like_url_re = r"^[^:]+@[^:]+:[^/]+/"
scp_like_url_re = r"^[^/:]+@[^/:]+:[^/]+/"
# If our URL is missing a schema and matches git's
# SCP-like syntax we should convert it to a proper

View File

@ -1139,6 +1139,17 @@ class NormalizeUrlTests(ManifestParseTestCase):
"http://foo.com/bar/baz", manifest_xml.normalize_url(url)
)
def test_has_leading_slash(self):
"""SCP-like syntax except a / comes before the : which git disallows."""
url = "/git@foo.com:bar/baf"
self.assertEqual(url, manifest_xml.normalize_url(url))
url = "gi/t@foo.com:bar/baf"
self.assertEqual(url, manifest_xml.normalize_url(url))
url = "git@fo/o.com:bar/baf"
self.assertEqual(url, manifest_xml.normalize_url(url))
def test_has_no_scheme(self):
"""Deal with cases where we have no scheme, but we also
aren't dealing with the git SCP-like syntax