furl
furl copied to clipboard
if path end with "/", then add one path start with "/" will become "//"
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'
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?
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