Skip to content

Commit 54a7d0a

Browse files
committed
Issue webcompat#767: normalize_url doesn't break when scheme is properly spelled
1 parent 6801fe8 commit 54a7d0a

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

tests/test_form.py

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ class TestForm(unittest.TestCase):
1111

1212
def test_normalize_url(self):
1313

14+
r = form.normalize_url('http://example.com')
15+
self.assertEqual(r, 'http://example.com')
16+
17+
r = form.normalize_url('https://example.com')
18+
self.assertEqual(r, 'https://example.com')
19+
1420
r = form.normalize_url('example.com')
1521
self.assertEqual(r, 'http://example.com')
1622

webcompat/form.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -121,22 +121,21 @@ def normalize_url(url):
121121
url = url.strip()
122122
parsed = urlparse.urlparse(url)
123123

124-
if url.startswith(BAD_SCHEMES):
124+
if url.startswith(BAD_SCHEMES) and not url.startswith(SCHEMES):
125125
# if url starts with a bad scheme, parsed.netloc will be empty,
126126
# so we use parsed.path instead
127127
path = parsed.path.lstrip('/')
128-
url = '%s://%s' % (parsed.scheme, path)
128+
url = '{}://{}'.format(parsed.scheme, path)
129129
if parsed.query:
130130
url += '?' + parsed.query
131131
if parsed.fragment:
132132
url += '#' + parsed.fragment
133133
elif not parsed.scheme:
134134
# We assume that http is missing not https
135135
if url.startswith("//"):
136-
url = "http://%s" % (url[2:])
136+
url = "http://{}".format(url[2:])
137137
else:
138-
url = 'http://%s' % (url)
139-
138+
url = 'http://{}'.format(url)
140139
return url
141140

142141

0 commit comments

Comments
 (0)