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

Extra slash in string representation. #103

Open
ejohb opened this issue Aug 22, 2018 · 4 comments
Open

Extra slash in string representation. #103

ejohb opened this issue Aug 22, 2018 · 4 comments

Comments

@ejohb
Copy link

ejohb commented Aug 22, 2018

Hi,

When I take a schemaless URL, and set a schema, the resulting string has an extra slash.

furl('www.example.com').set(scheme='http').tostr()

'http:///www.example.com'

Is that by design? Can I get rid of it?

@gruns
Copy link
Owner

gruns commented Aug 22, 2018

Absolutely not by design. Wonderful catch.

I'll rectify this shortly.

@gruns
Copy link
Owner

gruns commented Sep 5, 2018

I, too, got confused. This is intentional behavior. Albeit a bit of an initial
head scratcher.

See #85 and my detailed answer here #85 (comment).

Long story short: www.example.com looks like a domain to you and I, but
without URL delimiters (e.g. ://, /, ?, etc) furl can't consistently
determine whether www.example.com is a domain or a path. It can be both. It's
ambiguous.

Therefore, for consistent behavior, furl parses all such strings as paths.

So, to create your URL as intended, explicitly set www.example.com as
the host:

>>> from furl import furl
>>> furl().set(scheme='http', host='www.example.com').tostr()
'http://www.example.com'

Does that answer your question?

@gruns
Copy link
Owner

gruns commented Dec 17, 2018

Resolution of this Issue tied with the resolution of #110.

@pramttl
Copy link

pramttl commented Aug 5, 2021

I ran into the same confusion with triple slashes. Just a usability thught:

Can furl support specifying an is_domain boolean parameter that allows furl to treat the url as a domain and not a path..

furl(url, is_domain=True, scheme='https')

That way setting a scheme on a url which does not have one will become easier especially for the case of domains.

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