Bug 30103

Summary: Submitting an empty form with GET should not append a question mark
Product: WebKit Reporter: Erik Arvidsson <arv>
Component: FormsAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: ap, brettw, costan, mail, mtanalin
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: PC   
OS: OS X 10.5   

Description Erik Arvidsson 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
Comment 1 Alexey Proskuryakov 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.
Comment 2 Alexey Proskuryakov 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.
Comment 3 Erik Arvidsson 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.
Comment 4 Meixger 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/
Comment 5 Alexey Proskuryakov 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.
Comment 6 Victor Costan 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.
Comment 7 Marat Tanalin 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/