Skip to content

Commit

Permalink
Don't add a scheme to the input url of urlsplit(url) if one wasn't pr…
Browse files Browse the repository at this point in the history
…ovided originally.
  • Loading branch information
Arthur Grunseid committed Apr 13, 2012
1 parent 7f7e2d6 commit 8e86646
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions furl/furl.py
Expand Up @@ -663,6 +663,8 @@ def load(self, url):


tokens = urlsplit(url) # Raises ValueError on malformed IPv6 address. tokens = urlsplit(url) # Raises ValueError on malformed IPv6 address.


print 'tokens', tokens

self.netloc = tokens.netloc # Raises ValueError. self.netloc = tokens.netloc # Raises ValueError.
self.scheme = tokens.scheme.lower() self.scheme = tokens.scheme.lower()
if not self.port: if not self.port:
Expand Down Expand Up @@ -1047,6 +1049,11 @@ def urlsplit(url):
http://docs.python.org/library/urlparse.html#urlparse.urlsplit http://docs.python.org/library/urlparse.html#urlparse.urlsplit
""" """
# If a scheme wasn't provided, we shouldn't add one by setting the scheme to
# 'http'. We can use urlparse.urlsplit(url) as-is.
if '://' not in url:
return urlparse.urlsplit(url)

def _change_urltoks_scheme(tup, scheme): def _change_urltoks_scheme(tup, scheme):
l = list(tup) l = list(tup)
l[0] = scheme l[0] = scheme
Expand Down
6 changes: 6 additions & 0 deletions tests/test_furl.py
Expand Up @@ -1287,6 +1287,12 @@ def test_join(self):
assert f is f.join(join) and f.url == result assert f is f.join(join) and f.url == result


def test_urlsplit(self): def test_urlsplit(self):
# Without any delimeters like '://' or '/', the input should become a path.
urls = ['sup', '127.0.0.1', 'www.google.com', '192.168.1.1:8000']
for url in urls:
assert isinstance(furl.urlsplit(url), urlparse.SplitResult)
assert furl.urlsplit(url) == urlparse.urlsplit(url)

# No changes to existing urlsplit() behavior for known schemes. # No changes to existing urlsplit() behavior for known schemes.
url = 'http://www.pumps.com/' url = 'http://www.pumps.com/'
assert isinstance(furl.urlsplit(url), urlparse.SplitResult) assert isinstance(furl.urlsplit(url), urlparse.SplitResult)
Expand Down

0 comments on commit 8e86646

Please sign in to comment.