Bug 1591100. Fix the form submission URL for the empty-query case. r=smaug
authorBoris Zbarsky <bzbarsky@mit.edu>
Fri, 13 Mar 2020 11:46:26 +0000
changeset 518564 b8f97dccb4323773600e04b43931ee54ded2eb29
parent 518563 46dfbb4de902bd600b0fe78795c853b96c3467aa
child 518565 08766c2e3d6ae550662bff4648702d2570979955
push id37213
push usershindli@mozilla.com
push dateFri, 13 Mar 2020 21:46:16 +0000
treeherdermozilla-central@8ef0a54d7715 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1591100
milestone76.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1591100. Fix the form submission URL for the empty-query case. r=smaug Differential Revision: https://phabricator.services.mozilla.com/D66721
dom/html/HTMLFormSubmission.cpp
dom/html/test/test_bug297761.html
dom/html/test/test_bug557087-5.html
dom/html/test/test_bug567938-1.html
dom/html/test/test_bug567938-2.html
dom/html/test/test_bug567938-3.html
testing/web-platform/tests/html/semantics/forms/form-submission-0/form-submission-algorithm.html
toolkit/components/extensions/test/mochitest/test_ext_webnavigation.html
--- a/dom/html/HTMLFormSubmission.cpp
+++ b/dom/html/HTMLFormSubmission.cpp
@@ -277,17 +277,23 @@ nsresult FSURLEncoded::GetEncodedSubmiss
   } else {
     // Get the full query string
     if (aURI->SchemeIs("javascript")) {
       return NS_OK;
     }
 
     nsCOMPtr<nsIURL> url = do_QueryInterface(aURI);
     if (url) {
-      rv = NS_MutateURI(aURI).SetQuery(mQueryString).Finalize(aOutURI);
+      // Make sure that we end up with a query component in the URL.  If
+      // mQueryString is empty, nsIURI::SetQuery() will remove the query
+      // component, which is not what we want.
+      rv = NS_MutateURI(aURI)
+               .SetQuery(mQueryString.IsEmpty() ? NS_LITERAL_CSTRING("?")
+                                                : mQueryString)
+               .Finalize(aOutURI);
     } else {
       nsAutoCString path;
       rv = aURI->GetPathQueryRef(path);
       NS_ENSURE_SUCCESS(rv, rv);
       // Bug 42616: Trim off named anchor and save it to add later
       int32_t namedAnchorPos = path.FindChar('#');
       nsAutoCString namedAnchor;
       if (kNotFound != namedAnchorPos) {
--- a/dom/html/test/test_bug297761.html
+++ b/dom/html/test/test_bug297761.html
@@ -42,18 +42,18 @@ function nextTest()
     el.focus();
     el.click();
   }
 }
 
 function frameLoaded(aFrame)
 {
   var documentLocation = location.href.replace(/\.html.*/, "\.html");
-  is(aFrame.contentWindow.location.href.replace(/\?x=0&y=0/, ""),
-     documentLocation.replace(/test_bug/, "file_bug"),
+  is(aFrame.contentWindow.location.href.replace(/\?x=0&y=0/, "?"),
+     documentLocation.replace(/test_bug/, "file_bug") + "?",
      "form should have been submitted to the document location");
 
   if (++curTest == nbTests) {
     SimpleTest.finish();
   } else {
     nextTest();
   }
 }
--- a/dom/html/test/test_bug557087-5.html
+++ b/dom/html/test/test_bug557087-5.html
@@ -28,18 +28,18 @@ https://bugzilla.mozilla.org/show_bug.cg
 
 /** Test for Bug 557087 **/
 
 SimpleTest.waitForExplicitFinish();
 addLoadEvent(runTest);
 
 const BASE_URI = "http://mochi.test:8888/tests/dom/html/test/dummy_page.html";
 var testResults = [
-  BASE_URI,
-  BASE_URI,
+  BASE_URI + "?",
+  BASE_URI + "?",
   BASE_URI + "?i=i&t=t&s=s",
   BASE_URI + "?i=i&t=t&s=s",
 ];
 var gTestCount = 0;
 
 var form = document.forms[0];
 var iframe = document.getElementsByTagName('iframe')[0];
 var fieldsets = document.getElementsByTagName('fieldset');
--- a/dom/html/test/test_bug567938-1.html
+++ b/dom/html/test/test_bug567938-1.html
@@ -44,17 +44,17 @@ function initializeNextTest()
 
   sendMouseEvent({type: 'click'}, 'i');
 }
 
 function runTests()
 {
   document.getElementById('iframe').addEventListener('load', function(aEvent) {
     is(frames.submit_frame.location.href,
-       "http://mochi.test:8888/tests/dom/html/test/" + gTestData[gCurrentTest],
+       "http://mochi.test:8888/tests/dom/html/test/" + gTestData[gCurrentTest] + "?",
        "The form should have been submitted");
     gCurrentTest++;
     if (gCurrentTest < gTestData.length) {
       initializeNextTest();
     } else {
       aEvent.target.removeEventListener('load', arguments.callee);
       SimpleTest.finish();
     }
--- a/dom/html/test/test_bug567938-2.html
+++ b/dom/html/test/test_bug567938-2.html
@@ -45,17 +45,17 @@ function initializeNextTest()
 
   sendMouseEvent({type: 'click'}, 'i');
 }
 
 function runTests()
 {
   document.getElementById('iframe').addEventListener('load', function(aEvent) {
     is(frames.submit_frame.location.href,
-       "http://mochi.test:8888/tests/dom/html/test/" + gTestData[gCurrentTest],
+       "http://mochi.test:8888/tests/dom/html/test/" + gTestData[gCurrentTest] + "?",
        "The form should have been submitted");
     gCurrentTest++;
     if (gCurrentTest < gTestData.length) {
       initializeNextTest();
     } else {
       aEvent.target.removeEventListener('load', arguments.callee);
       SimpleTest.finish();
     }
--- a/dom/html/test/test_bug567938-3.html
+++ b/dom/html/test/test_bug567938-3.html
@@ -45,17 +45,17 @@ function initializeNextTest()
 
   sendMouseEvent({type: 'click'}, 'i');
 }
 
 function runTests()
 {
   document.getElementById('iframe').addEventListener('load', function(aEvent) {
     is(frames.submit_frame.location.href,
-       "http://mochi.test:8888/tests/dom/html/test/" + gTestData[gCurrentTest],
+       "http://mochi.test:8888/tests/dom/html/test/" + gTestData[gCurrentTest] + "?",
        "The form should have been submitted");
     gCurrentTest++;
     if (gCurrentTest < gTestData.length) {
       initializeNextTest();
     } else {
       aEvent.target.removeEventListener('load', arguments.callee);
       SimpleTest.finish();
     }
--- a/testing/web-platform/tests/html/semantics/forms/form-submission-0/form-submission-algorithm.html
+++ b/testing/web-platform/tests/html/semantics/forms/form-submission-0/form-submission-algorithm.html
@@ -138,10 +138,19 @@ async_test(t => {
     wasLoaded = true;
     assert_true(iframe.contentWindow.location.search.indexOf('n1=v1') == -1);
     t.done();
   });
   iframe.src = '/common/dummy.xhtml';
   assert_false(wasLoaded, 'Make sure the first loading is ongoing.');
   form.submit();
 }, 'Cannot navigate (after constructing the entry list)');
+
+promise_test(async () => {
+  let form = populateForm('<input type=submit>');
+  let iframe = form.previousSibling;
+  let event;
+  form.submit();
+  await loadPromise(iframe);
+  assert_true(iframe.contentWindow.location.href.includes("?"));
+}, 'Submission URL should always have a non-null query part');
 </script>
 </body>
--- a/toolkit/components/extensions/test/mochitest/test_ext_webnavigation.html
+++ b/toolkit/components/extensions/test/mochitest/test_ext_webnavigation.html
@@ -69,16 +69,17 @@ function backgroundScript() {
     browser.webNavigation[event].addListener(listeners[event]);
   }
 
   browser.test.sendMessage("ready");
 }
 
 const BASE = "http://mochi.test:8888/tests/toolkit/components/extensions/test/mochitest";
 const URL = BASE + "/file_WebNavigation_page1.html";
+const FORM_URL = URL + "?";
 const FRAME = BASE + "/file_WebNavigation_page2.html";
 const FRAME2 = BASE + "/file_WebNavigation_page3.html";
 const FRAME_PUSHSTATE = BASE + "/file_WebNavigation_page3_pushState.html";
 const REDIRECT = BASE + "/redirection.sjs";
 const REDIRECTED = BASE + "/dummy_page.html";
 const CLIENT_REDIRECT = BASE + "/file_webNavigation_clientRedirect.html";
 const CLIENT_REDIRECT_HTTPHEADER = BASE + "/file_webNavigation_clientRedirect_httpHeaders.html";
 const FRAME_CLIENT_REDIRECT = BASE + "/file_webNavigation_frameClientRedirect.html";
@@ -182,21 +183,21 @@ add_task(async function webnav_transitio
     is(found.details.transitionType, "auto_subframe",
        "Got the expected 'auto_subframe' transitionType in the OnCommitted event");
     ok(Array.isArray(found.details.transitionQualifiers),
        "transitionQualifiers found in the OnCommitted events");
   }
 
   // transitionType: form_submit
   received = [];
-  await loadAndWait(win, "onCompleted", URL, () => {
+  await loadAndWait(win, "onCompleted", FORM_URL, () => {
     win.document.querySelector("form").submit();
   });
 
-  found = received.find((data) => (data.event == "onCommitted" && data.url == URL));
+  found = received.find((data) => (data.event == "onCommitted" && data.url == FORM_URL));
 
   ok(found, "Got the onCommitted event");
 
   if (found) {
     is(found.details.transitionType, "form_submit",
        "Got the expected 'form_submit' transitionType in the OnCommitted event");
     ok(Array.isArray(found.details.transitionQualifiers),
        "transitionQualifiers found in the OnCommitted events");
@@ -215,19 +216,19 @@ add_task(async function webnav_transitio
        "Got the expected 'link' transitionType in the OnCommitted event");
     ok(Array.isArray(found.details.transitionQualifiers) &&
        found.details.transitionQualifiers.find((q) => q == "server_redirect"),
        "Got the expected 'server_redirect' transitionQualifiers in the OnCommitted events");
   }
 
   // transitionQualifier: forward_back
   received = [];
-  await loadAndWait(win, "onCompleted", URL, () => { win.history.back(); });
+  await loadAndWait(win, "onCompleted", FORM_URL, () => { win.history.back(); });
 
-  found = received.find((data) => (data.event == "onCommitted" && data.url == URL));
+  found = received.find((data) => (data.event == "onCommitted" && data.url == FORM_URL));
 
   ok(found, "Got the onCommitted event");
 
   if (found) {
     is(found.details.transitionType, "link",
        "Got the expected 'link' transitionType in the OnCommitted event");
     ok(Array.isArray(found.details.transitionQualifiers) &&
        found.details.transitionQualifiers.find((q) => q == "forward_back"),