File tree 2 files changed +10
-5
lines changed
2 files changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,12 @@ class TestForm(unittest.TestCase):
11
11
12
12
def test_normalize_url (self ):
13
13
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
+
14
20
r = form .normalize_url ('example.com' )
15
21
self .assertEqual (r , 'http://example.com' )
16
22
Original file line number Diff line number Diff line change @@ -121,22 +121,21 @@ def normalize_url(url):
121
121
url = url .strip ()
122
122
parsed = urlparse .urlparse (url )
123
123
124
- if url .startswith (BAD_SCHEMES ):
124
+ if url .startswith (BAD_SCHEMES ) and not url . startswith ( SCHEMES ) :
125
125
# if url starts with a bad scheme, parsed.netloc will be empty,
126
126
# so we use parsed.path instead
127
127
path = parsed .path .lstrip ('/' )
128
- url = '%s ://%s' % (parsed .scheme , path )
128
+ url = '{} ://{}' . format (parsed .scheme , path )
129
129
if parsed .query :
130
130
url += '?' + parsed .query
131
131
if parsed .fragment :
132
132
url += '#' + parsed .fragment
133
133
elif not parsed .scheme :
134
134
# We assume that http is missing not https
135
135
if url .startswith ("//" ):
136
- url = "http://%s" % (url [2 :])
136
+ url = "http://{}" . format (url [2 :])
137
137
else :
138
- url = 'http://%s' % (url )
139
-
138
+ url = 'http://{}' .format (url )
140
139
return url
141
140
142
141
You can’t perform that action at this time.
0 commit comments