From a744731f65b687e277a38186628347c27a7b0e93 Mon Sep 17 00:00:00 2001 From: matthias-p <53579673+matthias-p@users.noreply.github.com> Date: Wed, 5 Jan 2022 14:12:54 +0100 Subject: [PATCH] Update git ssh url pattern (#4057) * Add ssh:// url pattern to regex Add support for the ssh:// url pattern, since it is a valid ssh url. Also added the ~ sign to the repo pattern, because ssh and git protocol support ~username expansion Co-authored-by: Pijarowski, Matthias --- cvat-ui/src/utils/validation-patterns.ts | 4 ++-- cvat/apps/dataset_repo/dataset_repo.py | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cvat-ui/src/utils/validation-patterns.ts b/cvat-ui/src/utils/validation-patterns.ts index c0dc252f..9d536f79 100644 --- a/cvat-ui/src/utils/validation-patterns.ts +++ b/cvat-ui/src/utils/validation-patterns.ts @@ -1,4 +1,4 @@ -// Copyright (C) 2020-2021 Intel Corporation +// Copyright (C) 2021 Intel Corporation // // SPDX-License-Identifier: MIT @@ -66,7 +66,7 @@ const validationPatterns = { validateURL: { // eslint-disable-next-line - pattern: /^((https?:\/\/)|(git@))[^\s$.?#].[^\s]*$/, // url, ssh url, ip + pattern: /^((https?:\/\/)|((ssh:\/\/)?git@))[^\s$.?#].[^\s]*$/, // url, ssh url, ip message: 'URL is not valid', }, diff --git a/cvat/apps/dataset_repo/dataset_repo.py b/cvat/apps/dataset_repo/dataset_repo.py index b6ba56a9..2b9bdb32 100644 --- a/cvat/apps/dataset_repo/dataset_repo.py +++ b/cvat/apps/dataset_repo/dataset_repo.py @@ -71,7 +71,7 @@ class Git: # Method parses an got URL. - # SSH: git@github.com/proj/repos[.git] + # SSH: [ssh://]git@github.com/proj/repos[.git] # HTTP/HTTPS: [http://]github.com/proj/repos[.git] def _parse_url(self): try: @@ -80,8 +80,8 @@ class 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._-]+)+)" + http_pattern = r"(?:http[s]?://)?" + host_pattern + r"((?:/[a-zA-Z0-9._\-~]+){2,})" + ssh_pattern = r"(ssh://)?([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) @@ -94,9 +94,9 @@ class Git: host = http_match.group(1) repos = http_match.group(2)[1:] elif ssh_match: - user = ssh_match.group(1) - host = ssh_match.group(2) - repos = "{}{}".format(ssh_match.group(3), ssh_match.group(4)) + user = ssh_match.group(1) + ssh_match.group(2) if ssh_match.group(1) is not None else ssh_match.group(2) + host = ssh_match.group(3) + repos = "{}{}".format(ssh_match.group(4), ssh_match.group(5)) else: raise Exception("Git repository URL does not satisfy pattern")