Skip to content

Commit

Permalink
Strip functions take characters, not substrings
Browse files Browse the repository at this point in the history
  • Loading branch information
jace committed Aug 24, 2021
1 parent 0a94637 commit a0175b8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion baseframe/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,10 @@ def cleanurl_filter(url: Union[str, furl]) -> str:
if not isinstance(url, furl):
url = furl(url)
url.path.normalize()
netloc = url.netloc.lstrip('www.') if url.netloc else url.netloc
if url.netloc is not None and url.netloc.startswith('www.'):
netloc = url.netloc[4:]
else:
netloc = url.netloc
return furl().set(netloc=netloc, path=url.path).url.lstrip('//').rstrip('/')


Expand Down
2 changes: 2 additions & 0 deletions tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,8 @@ def test_cleanurl(self):
== "example.com/some/path"
)
assert filters.cleanurl_filter("http://www.example.com/") == "example.com"
assert filters.cleanurl_filter("https://example.com/") == "example.com"
assert filters.cleanurl_filter("https://windows.com/") == "windows.com"
assert filters.cleanurl_filter("//www.example.com/") == "example.com"
assert filters.cleanurl_filter("//test/") == "test"
# cannot process if scheme is missing and no // to begin with
Expand Down

0 comments on commit a0175b8

Please sign in to comment.