Skip to content

Commit

Permalink
Fixes regexes to accept multipart git repository address. (cvat-ai#1655)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
2 people authored and Fernando Martínez González committed Aug 3, 2020
1 parent 9b2a73c commit 7cc8571
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions cvat/apps/git/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ def _parse_url(self):
# 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)
Expand All @@ -95,7 +95,7 @@ def _parse_url(self):
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")

Expand Down
2 changes: 1 addition & 1 deletion cvat/apps/git/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def _check_correct_urls(self, samples):
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']

Expand Down

0 comments on commit 7cc8571

Please sign in to comment.