furl icon indicating copy to clipboard operation
furl copied to clipboard

Triple slashes

Open kaldown opened this issue 4 years ago • 1 comments

Although it is okay, still looks weird:

>>> f = furl('staging.s3-website.us-east-1.amazonaws.com')
>>> f.scheme = 'http'
>>> f.url
'http:///staging.s3-website.us-east-1.amazonaws.com'

Why is there triple slashes?

Additional:

>>> f = furl('http://staging.s3-website.us-east-1.amazonaws.com')
>>> f.url
'http://staging.s3-website.us-east-1.amazonaws.com'

But:

>>> f = furl('staging.s3-website.us-east-1.amazonaws.com')
>>> f.scheme = 'http://'  # yes, it's not a proper way, but still confusing how parser works
'http://:staging.s3-website.us-east-1.amazonaws.com'

I'm confused.

kaldown avatar Mar 18 '21 16:03 kaldown

see https://github.com/gruns/furl/issues/110 and https://github.com/gruns/furl/issues/103

in short, furl doesn't know whether to treat staging.s3-website.us-east-1.amazonaws.com as a path or a domain, as it can be both. so, to be unambiguous, it treats it as a path, resulting in 'http:///staging.s3-website.us-east-1.amazonaws.com' (with an empty host)

until furl knows the public suffix list (something i started working on but have yet to finish), you can avoid this by explicitly setting 'staging.s3-website.us-east-1.amazonaws.com' as the host, eg

>>> f = furl().set(host='staging.s3-website.us-east-1.amazonaws.com')
>>> f.url
'//staging.s3-website.us-east-1.amazonaws.com'

gruns avatar Mar 18 '21 19:03 gruns