RESOLVED INVALID 30103
Submitting an empty form with GET should not append a question mark
https://bugs.webkit.org/show_bug.cgi?id=30103
Summary Submitting an empty form with GET should not append a question mark
Erik Arvidsson
Reported 2009-10-05 18:27:55 PDT
If we submit a form using GET and there is no form data we should not append a question mark '?'. <form action="b.html" method="GET"></form> <button onclick="document.forms[0].submit()">Submit</button> This should navigate to "b.html" and not "b.html?" The bug seems to be in KURL::setQuery. It always adds a '?' no matter what http://trac.webkit.org/browser/trunk/WebCore/platform/KURL.cpp#L779 Brett, KURLGoogle has a comment that it does not add the '?' and that we need to eliminate this difference but it seems we always get the extra '?' with KURLGoogle as well. http://trac.webkit.org/browser/trunk/WebCore/platform/KURLGoogle.cpp#L652
Attachments
Alexey Proskuryakov
Comment 1 2009-10-06 08:42:41 PDT
> This should navigate to "b.html" and not "b.html?" Why should it? See bug 8051 - the form is not quite empty in that case, but that's close enough to question what the difference affecting behavior really is.
Alexey Proskuryakov
Comment 2 2009-10-07 21:37:30 PDT
Per a comment Erik added to bug 8051, Firefox doesn't do this (any more?). We need to test related cases thoroughly to determine if it's safe to undo this fix, and test IE, of course.
Erik Arvidsson
Comment 3 2009-10-08 09:32:40 PDT
Bug 8051 was about an empty form that was not submitted because the URL didn't change. The action attribute was set to "". We do need to submit the form in that case and this is what Firefox does. However, we should not add a '?'. This is important for another case when the form is empty and the action is set to a fragment identifier (#a). This is important for fixing bug 20342. I'm willing to fix this and 20342 if we can agree on the following Firefox's behavior.
Meixger
Comment 4 2012-04-27 03:15:03 PDT
any updates to this bug/behavior? We use form GET for tracking purposes, and some CMS breaks on urls with question marks. Here's a demo http://jsfiddle.net/a4TeB/
Alexey Proskuryakov
Comment 5 2012-04-27 08:47:39 PDT
We still lack results of IE testing. WebKit and IE together make a qualified majority of Web browsers, which is why it's important even if Firefox is different.
Victor Costan
Comment 6 2013-09-25 17:01:13 PDT
IE9 follows Firefox's behavior, but WebKit follows the standards. (in my understanding) The HTML5 forms TR says that method="GET" means the form data is URL-encoded, and the algorithm for that returns the empty string. The action URL mutating algorithm says the query is set to this empty string, and then the URL is serialized using the URL spec. The URL spec says that if the query is non-null, the URL gets a "?". Query computation: http://www.w3.org/TR/html5/forms.html#application/x-www-form-urlencoded-encoding-algorithm Action URL mutating: http://www.w3.org/TR/html5/forms.html#submit-mutate-action URL serializing: http://url.spec.whatwg.org/#serializing Assuming we want to follow Firefox / IE instead of the standard, fixing this bug should be a matter of reverting the KURL change and updating the layout test in https://bugs.webkit.org/show_bug.cgi?id=8051 Please let me know. I'd be happy to submit a patch.
Marat Tanalin
Comment 7 2015-07-17 06:33:53 PDT
All other major browsers work correctly and do NOT append question mark to URL in case of empty GET-method form, namely: * Firefox (at least version 4+), * Opera 12 (Opera before switching to Chromium), * Internet Explorer (at least version 8+), * Microsoft Edge (Windows 10's brand new browser). That's just common sense since the `?` separator is unneeded if there is nothing to separate (query string is empty). Forms without fields are a valid way for creating buttons that effectively act as links that always point to the same exact URL [1]. WebKit and its fork named Chromium are currently the only engines that need the workaround based on server-side redirection [2]. [1] http://tanalin.com/en/blog/2013/03/link-button/ [2] http://tanalin.com/en/blog/2015/05/empty-query-string/
Anne van Kesteren
Comment 8 2024-08-29 06:18:23 PDT
It's now standardized to always output a question mark (query is always set to a string in "Mutate action URL"). (This also appears to be what Chrome, Firefox, and Safari implement.)
Marat Tanalin
Comment 9 2024-08-29 15:20:56 PDT
> It's now standardized A link probably? > This also appears to be what Chrome, Firefox, and Safari implement. Firefox previously did not add the redundant question mark, but Firefox 76+ apparently do: https://bugzilla.mozilla.org/show_bug.cgi?id=1591100 Among modern browsers, Vivaldi (tested 6.6.3271.53 and the latest 6.9.3447.37) seems to still do the right thing according to common sense — not to add the separator when there is nothing to separate.
Note You need to log in before you can comment on or make changes to this bug.