|
25 | 25 | AUTH_REPORT = 'github-auth-report'
|
26 | 26 | PROXY_REPORT = 'github-proxy-report'
|
27 | 27 | SCHEMES = ('http://', 'https://')
|
| 28 | +BAD_SCHEMES = ('http:/', 'https:/', 'http:', 'https:') |
28 | 29 |
|
29 | 30 | problem_choices = [
|
30 | 31 | (u'detection_bug', u'Desktop site instead of mobile site'),
|
@@ -118,9 +119,25 @@ def get_labels(browser_name):
|
118 | 119 | def normalize_url(url):
|
119 | 120 | '''normalize URL for consistency.'''
|
120 | 121 | url = url.strip()
|
121 |
| - if not url.startswith(SCHEMES): |
| 122 | + parsed = urlparse.urlparse(url) |
| 123 | + |
| 124 | + if url.startswith(BAD_SCHEMES): |
| 125 | + # if url starts with a bad scheme, parsed.netloc will be empty, |
| 126 | + # so we use parsed.path instead |
| 127 | + path = parsed.path.lstrip('/') |
| 128 | + url = '%s://%s' % (parsed.scheme, path) |
| 129 | + if parsed.query: |
| 130 | + url += '?' + parsed.query |
| 131 | + if parsed.fragment: |
| 132 | + url += '#' + parsed.fragment |
| 133 | + elif not parsed.scheme: |
122 | 134 | # We assume that http is missing not https
|
123 | 135 | url = 'http://%s' % (url)
|
| 136 | + |
| 137 | + # if url does not contain a path, ensure it has a trailing slash |
| 138 | + if not urlparse.urlparse(url).path: |
| 139 | + url += "/" |
| 140 | + |
124 | 141 | return url
|
125 | 142 |
|
126 | 143 |
|
|
0 commit comments