Closed Bug 1591100 Opened 2 years ago Closed 2 years ago

Form submission with empty query string submits to wrong URL

Categories

(Core :: DOM: Core & HTML, defect, P2)

defect

Tracking

()

RESOLVED FIXED
mozilla76
Tracking Status
firefox76 --- fixed

People

(Reporter: bzbarsky, Assigned: bzbarsky)

Details

Attachments

(1 file)

STEPS TO REPRODUCE:

  1. Load http://example.com
  2. Open web console.
  3. 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...

Flags: needinfo?(valentin.gosu)

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.

Flags: needinfo?(valentin.gosu)
Priority: -- → P2
Assignee: nobody → bzbarsky
Status: NEW → ASSIGNED
Pushed by bzbarsky@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/b8f97dccb432
Fix the form submission URL for the empty-query case. r=smaug
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/22239 for changes under testing/web-platform/tests
Upstream web-platform-tests status checks passed, PR will merge once commit reaches central.
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla76
Upstream PR merged by moz-wptsync-bot
You need to log in before you can comment on or make changes to this bug.