gitweb: use CGI with -utf8 to process Unicode query parameters correctlygitweb/CGI-utf8-vA-pragma
commited72807a169f743b16b71241312f6ad63a4fa0b3
authorMichał Kiedrowicz <michal.kiedrowicz@gmail.com>
Wed, 1 Feb 2012 22:50:53 +0000 (1 23:50 +0100)
committerJakub Narebski <jnareb@gmail.com>
Thu, 2 Feb 2012 20:21:09 +0000 (2 21:21 +0100)
treefe41185670f3e55583613319c63e7f5b50138031
parentf3fb07509c2e0b21b12a598fcd0a19a92fc38a9d
gitweb: use CGI with -utf8 to process Unicode query parameters correctly

Gitweb tries hard to properly process UTF-8 data, by marking output
from git commands and contents of files as UTF-8 with to_utf8()
subroutine.  This ensures that gitweb would print correctly UTF-8
e.g. in 'log' and 'commit' views.

Unfortunately it misses another source of potentially Unicode input,
namely query parameters.  The result is that one cannot search for a
string containing characters outside US-ASCII.  For example searching
for "Michał Kiedrowicz" (containing letter 'ł' - LATIN SMALL LETTER L
WITH STROKE, with Unicode codepoint U+0142, represented with 0xc5 0x82
bytes in UTF-8 and percent-encoded as %C5%81) result in the following
incorrect data in search field

Michał Kiedrowicz

This is caused by CGI by default treating '0xc5 0x82' bytes as two
characters in Perl legacy encoding latin-1 (iso-8859-1), because 's'
query parameter is not processed explicitly as UTF-8 encoded string.

According to "Using Unicode in a Perl CGI script" article on
http://www.lemoda.net/cgi/perl-unicode/index.html the simplest
solution is to just import '-utf8' pragma for CGI module:

use CGI '-utf8';
my $value = params('input');

According to CGI module documentation, the '-utf8' pragma may cause
problems with POST requests containing binary files... but gitweb
currently do not use POST requests at all, so this should be not a
problem now.

Alternate solution would be to explicity decode query parameters when
storing them in %input_params (and perhaps also path_info).

[jn: reworded / rewritten commit message]

DOESN'T ACTUALLY WORK FOR CGI.pm 3.10 !!!

Signed-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com>
Signed-off-by: Jakub Narębski <jnareb@gmail.com>
gitweb/gitweb.perl