gitweb.perl: use correct enctype with get method
commit122e9a3177c1610927f5654aab87637844d61412
authorKyle J. McKay <mackyle@gmail.com>
Sat, 16 Nov 2019 20:59:42 +0000 (16 13:59 -0700)
committerKyle J. McKay <mackyle@gmail.com>
Sat, 16 Nov 2019 20:59:42 +0000 (16 13:59 -0700)
tree0491df8ed770665b94fedd852e73e9b468f6d1b8
parentfcfa13b1e53a9b998043441140926bc5170158f6
gitweb.perl: use correct enctype with get method

Once upon a time in the long distant past, the perl CGI module did
not know anything about XHTML or multipart/form-data.

When "start_form" (or as it was known then "startform") was called,
it spit out the method and action passed to it as-is and perhaps
added an `enctype="application/x-www-form-urlencoded"` attribute too.

But then CGI grew and changed discarding the old "startform" in favor
of the new "start_form" (with some limited-time backwards compatibility
for the old name).  And it learned about XHTML and multipart/form-data.

And in its zeal to produce the newest and shiniest output, started
outputting XHTML by default and assuming that in an XHTML environment
forms would always be using a POST method and that a POST method would,
of course, necessitate using the new and shiny multipart/form-data enctype.

Unfortunately for those clients actually using a GET method, while CGI did
honor and output the passed-in GET method, alas it ignored any passed-in
enctype and always output multipart/form-data when in XHTML mode even for
a method of GET for which multipart/form-data is not valid.

Eventually this problem was corrected but then as a reward for all its
hard work over the years, CGI was dumped from the core Perl distribution
and use of its "generation" functions completely deprecated even when
the latest non-core version of CGI has been installed.

In order to properly fix the "GET" using "multipart/form-data" problem, all
of the following need to be handled:

 1) old versions of CGI with the bug need to output the correct enctype
 2) newish versions of CGI without the bug need to output the correct enctype
 3) expelled, non-core versions of CGI need to output the correct enctype

Possible, but discarded fixes:

  * Use the old name "startform" as it never has the bug

    Discarded because it breaks with #3 above as "startform" is no
    longer present.

  * Explicitly provide the enctype "application/x-www-form-urlencoded"

    While this works for #2 and #3, unfortunately the buggy #1 ignores
    it and still outputs multipart/form-data.

  * Don't call start_form at all and just print the form start tag

    While this is okay with #1, it breaks #2 and #3 because the
    start_form call itself has side effects and if any other form
    generation functions are called (they are) they will not function
    properly.

The finally implemented solution does these two things:

 1) continues to call "start_form" exactly as before to make sure
    the side effects happen, but discards the result string (which
    is the form start tag string).

 2) prints out the form start tag exactly as desired being careful
    to make sure the action value is properly escaped.

This works for all versions of CGI that gitweb.perl supports and
always produces the correct enctype value.

Signed-off-by: Kyle J. McKay <mackyle@gmail.com>
gitweb/gitweb.perl