# HG changeset patch # User Mads Kiilerich # Date 2020-12-03 10:39:32 # Node ID 526c8751d75bb094d929c0a4afb1486abe94de54 # Parent 29d8bdab74dcfc4b9d5a9a6beee9b9aea59e51d2 vcs: add doc tests for git _check_url diff --git a/kallithea/lib/vcs/backends/git/repository.py b/kallithea/lib/vcs/backends/git/repository.py --- a/kallithea/lib/vcs/backends/git/repository.py +++ b/kallithea/lib/vcs/backends/git/repository.py @@ -149,11 +149,46 @@ class GitRepository(BaseRepository): @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: + >>> GitRepository._check_url('file:///repo') + Traceback (most recent call last): + ... + urllib.error.URLError: + >>> GitRepository._check_url('git+http://example.com/repo') + Traceback (most recent call last): + ... + urllib.error.URLError: + >>> GitRepository._check_url('git://example.com/%09') + Traceback (most recent call last): + ... + urllib.error.URLError: + >>> GitRepository._check_url('git://example.com/%x00') + Traceback (most recent call last): + ... + urllib.error.URLError: + >>> GitRepository._check_url(r'git://example.com/\u0009') + Traceback (most recent call last): + ... + urllib.error.URLError: + >>> GitRepository._check_url(r'git://example.com/\t') + Traceback (most recent call last): + ... + urllib.error.URLError: + >>> GitRepository._check_url('git://example.com/\t') + Traceback (most recent call last): + ... + urllib.error.URLError: """ # check first if it's not an local url if os.path.isabs(url) and os.path.isdir(url): @@ -175,7 +210,7 @@ class GitRepository(BaseRepository): 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)