Side navigation
#9658 closed bug (invalid)
Opened June 23, 2011 02:10PM UTC
Closed July 01, 2011 12:16AM UTC
Last modified July 01, 2011 12:21AM UTC
$.ajax should not prepend & to query string data when joining it to a url ending with ?
Reported by: | abarrett | Owned by: | abarrett |
---|---|---|---|
Priority: | low | Milestone: | 1.next |
Component: | ajax | Version: | git |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
An ampersand is unnecessarily prepended to the query string data of a GET request when the URL ends with a question mark.
$.get('foo?', { bar: 42 });
The above example will fetch the URL foo?&bar=42
instead of foo?bar=42
.
Concatenation of the URL and query string appears to be performed in ajax.js@L646, with an additional concatenation at L660 when attempting to defeat caching mechanisms.
Those two lines seem to be the only places the rquery regexp is used.
The example may look contrived, but I stumbled across this when using a simple ?
as the URL to fetch the current resource with a different query string.
Attachments (0)
Change History (4)
Changed June 29, 2011 07:14PM UTC by comment:1
component: | unfiled → ajax |
---|---|
owner: | → abarrett |
priority: | undecided → low |
status: | new → pending |
Changed June 29, 2011 07:45PM UTC by comment:2
status: | pending → new |
---|
Here is a QUnit test case against edge on jsFiddle: http://jsfiddle.net/alexb/mLS45/
Changed July 01, 2011 12:16AM UTC by comment:3
resolution: | → invalid |
---|---|
status: | new → closed |
If you put the question mark in your url, then ajax has to append the parameters the way it does. It cannot guess whether this is intentional on your part or not and takes the safest route, in case this is part of a custom query string scheme that would accept empty string as some kind of id (think myurl?service¶m1=value1&...).
Changed July 01, 2011 12:21AM UTC by comment:4
Replying to [comment:3 jaubourg]:
If you put the question mark in your url, then ajax has to append the parameters the way it does. It cannot guess whether this is intentional on your part or not and takes the safest route, in case this is part of a custom query string scheme that would accept empty string as some kind of id (think myurl?service¶m1=value1&...).
That is a valid point.
How about supporting the special case of a single ?
as the URL? As far as I am aware, there is no other way to request the current resource with a different query string.
Thanks for taking the time to contribute to the jQuery project! Please provide a reduced test case on http://jsfiddle.net that reproduces the issue experienced to help us assess your ticket.
Additionally, test against the jQuery (edge) version to ensure the issue still exists.