Mercurial > kallithea
changeset 8764:526c8751d75b
vcs: add doc tests for git _check_url
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Thu, 03 Dec 2020 10:39:32 +0100 |
parents | 29d8bdab74dc |
children | d2f59de17bef |
files | kallithea/lib/vcs/backends/git/repository.py |
diffstat | 1 files changed, 37 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/lib/vcs/backends/git/repository.py Mon Nov 16 14:38:40 2020 +0100 +++ b/kallithea/lib/vcs/backends/git/repository.py Thu Dec 03 10:39:32 2020 +0100 @@ -149,11 +149,46 @@ @staticmethod def _check_url(url): - """ + r""" Raise URLError if url doesn't seem like a valid safe Git URL. We only allow http, https, git, and ssh URLs. For http and https URLs, make a connection and probe to see if it is valid. + + >>> GitRepository._check_url('git://example.com/my%20fine repo') + + >>> GitRepository._check_url('foo') + Traceback (most recent call last): + ... + urllib.error.URLError: <urlopen error Unsupported protocol in URL 'foo'> + >>> GitRepository._check_url('file:///repo') + Traceback (most recent call last): + ... + urllib.error.URLError: <urlopen error Unsupported protocol in URL 'file:///repo'> + >>> GitRepository._check_url('git+http://example.com/repo') + Traceback (most recent call last): + ... + urllib.error.URLError: <urlopen error Unsupported protocol in URL 'git+http://example.com/repo'> + >>> GitRepository._check_url('git://example.com/%09') + Traceback (most recent call last): + ... + urllib.error.URLError: <urlopen error Invalid escape character in path: '%'> + >>> GitRepository._check_url('git://example.com/%x00') + Traceback (most recent call last): + ... + urllib.error.URLError: <urlopen error Invalid escape character in path: '%'> + >>> GitRepository._check_url(r'git://example.com/\u0009') + Traceback (most recent call last): + ... + urllib.error.URLError: <urlopen error Invalid escape character in path: '\'> + >>> GitRepository._check_url(r'git://example.com/\t') + Traceback (most recent call last): + ... + urllib.error.URLError: <urlopen error Invalid escape character in path: '\'> + >>> GitRepository._check_url('git://example.com/\t') + Traceback (most recent call last): + ... + urllib.error.URLError: <urlopen error Invalid whitespace character in path: '\t'> """ # check first if it's not an local url if os.path.isabs(url) and os.path.isdir(url): @@ -175,7 +210,7 @@ return if not url.startswith('http://') and not url.startswith('https://'): - raise urllib.error.URLError("Unsupported protocol in URL %s" % url) + raise urllib.error.URLError("Unsupported protocol in URL %r" % url) url_obj = mercurial.util.url(safe_bytes(url)) test_uri, handlers = get_urllib_request_handlers(url_obj)