-
Notifications
You must be signed in to change notification settings - Fork 526
Bugfix: Make util/request-url handle empty query string #543
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
base: master
Are you sure you want to change the base?
Conversation
|
Thanks for the pull request, and apologies for taking a little while to get round to reviewing this. The code looks fine, but we'll need to update the commit message to adhere to the contributing guidelines. Can you change the commit message to: |
This avoids generating URLs with a trailing '?'.
|
Thanks, no worries! Apologies for not checking those guidelines. Updated now. |
|
Thanks! Let me think about this fix a little, as on reflection I'm a little less certain about it. Aside from ring-mock, do you know of any other libraries that generate a blank query string? |
No, both http-kit and undertow-adapter give :query-string = nil for no query string. IMO, logically, nil and empty string should be equivalent in this case. Unless you for some reason wanted to preserve a trailing ? - which to me seems a bit crazy. But for my use case, if ring-mock stopped putting in the empty query string the problem would also go away. |
|
My reservation is that an absent query string and a blank query string are different things when parsing a URL. For instance, I'd expect Given that, producing a URL from a request map should maybe do the reverse; that is, parsing a URL into a request map, then generating a URL from the request map should end up with the original URL. I'm wondering in this case if it would be better to fix ring-mock. |
|
I can see the logic. Shall I make the change to ring mock instead then? |
|
Oh, yes please. I think that would be a good change to make regardless. I'll keep this PR open a little while longer while I consider it, though. |
|
Looking into it - ring mock only adds the query-string: "" when you pass it an empty map of parameters. For nil, it doesn't include the query-string at all. Are you still up for me to change it to make nil and {} params equivalent, i.e not include the query-string? Considering it then breaks the "symmetry" if you will. IMO, while I see the theoretical reasons for wanting to distinguish no query string and an empty one - in practice it's just confusing to have them be considered separate. I can't imagine any case where you'd want anyone to see the www.example.com/? type URL. |
Hello. I didn't make a separate issue, as I think the code itself most easily explains this problem.
The bug
Empty query strings would make request-url insert a trailing ? in the url for no reason. While not strictly invalid, it's a bit ugly. Empty query strings are added by ring.mock.request/request when you pass in an empty map for parameters.
Fix
This fixes that by checking that the query string is not empty before adding the ?.
Thanks in advance for your attention!