Fixes regexes to accept multipart git repository address. (#1655)

* Fixes regexes to accept multipart git repository address.

* Added test case for multi level path.

* Reduced complexity of SSH regex.

* Fixing unit tests.

* Fix SSH formatting.

Co-authored-by: kpawelczyk <kpawelczyk@future-processing.com>
main
AzaelCicero 6 years ago committed by GitHub
parent 4f991ddce5
commit 9320baeeb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -78,9 +78,9 @@ class Git:
# Reference on URL formats accepted by Git:
# https://github.com/git/git/blob/77bd3ea9f54f1584147b594abc04c26ca516d987/url.c
host_pattern = r"((?:(?:(?:\d{1,3}\.){3}\d{1,3})|(?:[a-zA-Z0-9._-]+.[a-zA-Z]+))(?::\d+)?)"
http_pattern = r"(?:http[s]?://)?" + host_pattern + r"((?:/[a-zA-Z0-9._-]+){2})"
ssh_pattern = r"([a-zA-Z0-9._-]+)@" + host_pattern + r":([a-zA-Z0-9._-]+)/([a-zA-Z0-9._-]+)"
host_pattern = r"((?:(?:(?:\d{1,3}\.){3}\d{1,3})|(?:[a-zA-Z0-9._-]+[.a-zA-Z]+))(?::\d+)?)"
http_pattern = r"(?:http[s]?://)?" + host_pattern + r"((?:/[a-zA-Z0-9._-]+){2,})"
ssh_pattern = r"([a-zA-Z0-9._-]+)@" + host_pattern + r":([a-zA-Z0-9._-]+)((?:/[a-zA-Z0-9._-]+)+)"
http_match = re.match(http_pattern, self._url)
ssh_match = re.match(ssh_pattern, self._url)
@ -95,7 +95,7 @@ class Git:
elif ssh_match:
user = ssh_match.group(1)
host = ssh_match.group(2)
repos = "{}/{}".format(ssh_match.group(3), ssh_match.group(4))
repos = "{}{}".format(ssh_match.group(3), ssh_match.group(4))
else:
raise Exception("Git repository URL does not satisfy pattern")

@ -28,7 +28,7 @@ class GitUrlTest(TestCase):
def test_correct_urls_can_be_parsed(self):
hosts = ['host.zone', '1.2.3.4']
ports = ['', ':42']
repo_groups = ['repo', 'r4p0']
repo_groups = ['repo', 'r4p0', 'multi/group', 'multi/group/level']
repo_repos = ['nkjl23', 'hewj']
git_suffixes = ['', '.git']

Loading…
Cancel
Save