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

if path end with "/", then add one path start with "/" will become "//" #145

Open
sankforever opened this issue Jul 9, 2021 · 2 comments

Comments

@sankforever
Copy link

In [2]: u = furl("https://www.baidu.com/aaa") / "/bbbb/ccc"
In [3]: u.url
Out[3]: 'https://www.baidu.com/aaa/bbbb/ccc'
In [4]: u = furl("https://www.baidu.com/aaa/") / "/bbbb/ccc"
In [6]: u.url
Out[6]: 'https://www.baidu.com/aaa//bbbb/ccc'

@gruns
Copy link
Owner

gruns commented Jul 9, 2021

this isn't an outright bug, as 'https://www.baidu.com/aaa//bbbb/ccc', with back to back //, is a perfectly valid url. furl doesn't prevent you from creating such urls. you can always do

>>> f = furl()
>>> f.path = 'a////b'
>>> f.url
'a////b'

if you want to remove the back to back //, you can normalize() the path. eg

>>> from furl import furl
>>> f = furl('https://www.baidu.com/aaa//bbbb/ccc')
>>> f.path.normalize()
>>> f.url
'https://www.baidu.com/aaa/bbbb/ccc'

does furl.path.normalize() solve your problem?

@sshishov
Copy link

sshishov commented Mar 10, 2023

Hello @gruns , can we have a parameter for furl to normalize by default. when you are calling obj.url for instance.

For me it is okay to store internally everything not normalized, but I would like to get at the end normalized path/url.

Another question is, can we support the settings on furl class to have the trailing slash always or never for instance. I would like to create url, add path segments to it and always be sure that it ends with a trailing slash. Sometimes we are adding dynamic user input strings and we do not want to check everything by ourselves.

current solution:

f = furl(url='https://example.com/hello/' / some_var_path / '/')
f.path.normalize()
return f.url

It looks so unnatural and instead of 1 line I should write 3 lines to make sure I do not have double slashes and also I do have trailing slash (see this / '/' at the end?!

It would be great like:

return furl(url='https://example.com/hello/' / some_var_path, normalize=True, trailing_slash=True).url

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants