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

Value less query params are not preserved exactly #22

Closed
ulope opened this issue Nov 1, 2013 · 6 comments
Closed

Value less query params are not preserved exactly #22

ulope opened this issue Nov 1, 2013 · 6 comments

Comments

@ulope
Copy link

ulope commented Nov 1, 2013

This fails:

url = "http://host/?param"
assert str(furl(url)) == url

I have to talk to a very picky web-service that needs a specific parameter to have no value (and not an empty value). However Furl generates ?param= with an empty value. Maybe using None for no value would work?

@gruns
Copy link
Owner

gruns commented Nov 3, 2013

A user's expectation of None would be ?param=, not ?param. The former is
more common. To be explicit

>>> f = furl('http://www.google.com/')
>>> f.args['sup'] = None
>>> f.url
'http://www.google.com/?sup='

instead of

>>> f = furl('http://www.google.com/')
>>> f.args['sup'] = None
>>> f.url
'http://www.google.com/?sup'

I can't recall the last time I saw the latter in the wild.

The current behavior serializes None to a string

>>> f = furl('http://www.google.com/')
>>> f.args['sup'] = None
>>> f.url
'http://www.google.com/?sup=None'

But I agree: None would be useful as a special value.

I'll ruminate on a potential solution for ?param. None as such would break a
lot of people's expectations.

Do you have any other ideas?

@nvie
Copy link

nvie commented Nov 4, 2013

Why not ?sup for sup = None and ?sup= for sup = ''?

@ulope
Copy link
Author

ulope commented Nov 4, 2013

Why not ?sup for sup = None and ?sup= for sup = ''?

Yes, thats how I meant it.

@gruns:
You wrote yourself that None currently isn't producing a very useful result - so I think there has to be no concern regarding backwards compatibility.

@gruns
Copy link
Owner

gruns commented Nov 6, 2013

Why not ?sup for sup = None and ?sup= for sup = ''?

That's how I understood @ulope.

The problem is the aforementioned breaks user expectations. ?sup=
is much more common than ?sup, so a new user would expect f.args['sup'] = None to become ?sup=, not ?sup.

That said, I don't see an obviously better way of supporting ?sup. Ruling out
the above, a furl constant could be used, like subprocess.PIPE

>>> f = furl('http://www.google.com/')
>>> f.args['sup'] = furl.EMPTY
>>> f.url
'http://www.google.com/?sup'

But that's mediocre at best.

Any other ideas before I implement f.args['sup'] = None as ?sup and f.args['sup'] = '' as ?sup=?

@gruns
Copy link
Owner

gruns commented Nov 12, 2013

Support for query parameters without a trailing =, as discussed above, was added to furl v0.3.6.

>>> f = furl('http://sprop.su')
>>> f.args['param'] = None
>>> f.url
'http://sprop.su/?param'

Upgrade with

pip install furl --upgrade

Thank you for bringing this issue to my attention @ulope.

@gruns gruns closed this as completed Nov 12, 2013
@nvie
Copy link

nvie commented Nov 12, 2013

👍

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