Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes regexes to accept multipart git repository address. #1655

Merged
merged 5 commits into from
Jun 14, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cvat/apps/git/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ def _parse_url(self):
# 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._-]+)"
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._-]+)*)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the last * should be +, as with * user@domain.zone:repo is valid.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, good observation.


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