Form submission with empty query string submits to wrong URL
Categories
(Core :: DOM: Core & HTML, defect, P2)
Tracking
()
Tracking | Status | |
---|---|---|
firefox76 | --- | fixed |
People
(Reporter: bzbarsky, Assigned: bzbarsky)
Details
Attachments
(1 file)
STEPS TO REPRODUCE:
- Load http://example.com
- Open web console.
- Evaluate
var form = document.createElement("form"); document.body.appendChild(form); form.submit()
EXPECTED RESULTS: Loaded URL is "http://example.com/?"
; see bug 1586740 comment 7 for the reasoning.
ACTUAL RESULTS: Loaded URL is "http://example.com"
.
This is happening because at https://searchfox.org/mozilla-central/rev/088e2cf29c59d733d57af43903eb0267dbf72e2a/dom/html/HTMLFormSubmission.cpp#290 we use SetQuery
, which treats empty string as "remove the query".
Valentin, is there any way to make this work apart from prepending "?"
to the query on the caller side, which will force a copy of the entire query string, as far as I can tell? The spec has a distinction between "set query to empty string" and "set query to null" which doesn't map well to what our URI classes do...
Comment 1•5 years ago
|
||
The API doesn't handle this case automatically, but if calling SetQuery with an empty string is the only issue with this, I assume we can change the callsite to say something like:
rv = NS_MutateURI(aURI).SetQuery(mQueryString.IsEmpty() ? NS_LITERAL_CSTRING("?") : mQueryString).Finalize(aOutURI);
It's less risky than trying to change the behaviour of SetQuery, and less intricate than adding a new method deals with this case specifically.
Updated•5 years ago
|
Assignee | ||
Comment 2•5 years ago
|
||
Updated•5 years ago
|
Comment 6•5 years ago
|
||
bugherder |
Description
•