launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #24272
[Merge] ~cjwatson/launchpad:testfix-remove-urllib-splittype into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:testfix-remove-urllib-splittype into launchpad:master.
Commit message:
Fix base_url_permutations following removal of urllib.splittype
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/378344
It turns out that one test did depend on the behaviour of base_url_permutations when given a particular kind of invalid URL, that is, one with neither scheme nor netloc (e.g. what you get if you just omit http:// or https:// from the start of a normal HTTP(S) URL). This seems like a reasonable thing to support, so adjust things slightly to do so.
See https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/378044 for the change this is fixing.
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:testfix-remove-urllib-splittype into launchpad:master.
diff --git a/lib/lp/bugs/model/bugtracker.py b/lib/lp/bugs/model/bugtracker.py
index 482934c..21375c7 100644
--- a/lib/lp/bugs/model/bugtracker.py
+++ b/lib/lp/bugs/model/bugtracker.py
@@ -95,17 +95,25 @@ def base_url_permutations(base_url):
>>> base_url_permutations('http://foo/bar')
['http://foo/bar', 'http://foo/bar/',
'https://foo/bar', 'https://foo/bar/']
+ >>> base_url_permutations('example.org/bar')
+ ['example.org/bar',
+ 'http://example.org/bar', 'http://example.org/bar/',
+ 'https://example.org/bar', 'https://example.org/bar/']
"""
http_schemes = ['http', 'https']
url_scheme, netloc, path, query, fragment = urlsplit(base_url)
if not url_scheme or url_scheme in http_schemes:
possible_schemes = http_schemes
- # Ensure that the path starts with a single slash.
- path = '/' + path.lstrip('/')
else:
# This else-clause is here since we have no strict
# requirement that bug trackers have to have http URLs.
possible_schemes = [url_scheme]
+ # If there's no netloc, try to make one out of the first segment of the
+ # path.
+ if not netloc:
+ netloc, _, path = path.partition('/')
+ # Ensure that the path starts with a single slash.
+ path = '/' + path.lstrip('/')
alternative_urls = [base_url]
for scheme in possible_schemes:
url = urlunsplit((scheme, netloc, path, query, fragment))