Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip functions take characters, not substrings #373

Merged
merged 1 commit into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Strip functions take characters, not substrings
  • Loading branch information
jace committed Aug 24, 2021
commit a0175b89a99f8d112710b61cdb53a7428a9e71e5
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