git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] gitweb: fix UTF-8 encoding when using CGI::Fast

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 29, 2020, 16:06 UTC
Message-ID
<xmqqr1xbb0xr.fsf@gitster.c.googlers.com>
In-Reply-To
<20200329002028.26080-1-julm+git@sourcephile.fr>
Julien Moutinho <julm+git@sourcephile.fr> writes:
Show 5 quoted lines
>  	require CGI::Fast;
>  	our $CGI = 'CGI::Fast';
> +	# FCGI is not Unicode aware hence the UTF-8 encoding must be done manually.
> +	# However no encoding must be done within git_blob_plain() and git_snapshot()
> +	# which must still output in raw binary mode.

I guess this comment would be sufficient to help future developers when they find that newer version of CGI::Fast has become Unicode aware later can make this part conditional to the version of the module, perhaps?

Would "use CGI::Fast (-utf8)" instead of the whole thing help, by the way?

Show 10 quoted lines
> +	no warnings 'redefine';
> +	my $enc = Encode::find_encoding('UTF-8');
> +	*FCGI::Stream::PRINT = sub {
> +		my @OUTPUT = @_;
> +		for (my $i = 1; $i < @_; $i++) {
> +			$OUTPUT[$i] = $enc->encode($_[$i], Encode::FB_CROAK|Encode::LEAVE_SRC);
> +		}
> +		@_ = @OUTPUT;
> +		goto $FCGI_Stream_PRINT_raw;
> +	};
Show 18 quoted lines
>  	my $request_number = 0;
>  	# let each child service 100 requests
> @@ -7079,6 +7093,7 @@ sub git_blob_plain {
>  			($sandbox ? 'attachment' : 'inline')
>  			. '; filename="' . $save_as . '"');
>  	local $/ = undef;
> +	local *FCGI::Stream::PRINT = $FCGI_Stream_PRINT_raw;
>  	binmode STDOUT, ':raw';
>  	print <$fd>;
>  	binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
> @@ -7417,6 +7432,7 @@ sub git_snapshot {
>  
>  	open my $fd, "-|", $cmd
>  		or die_error(500, "Execute git-archive failed");
> +	local *FCGI::Stream::PRINT = $FCGI_Stream_PRINT_raw;
>  	binmode STDOUT, ':raw';
>  	print <$fd>;
>  	binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
Previous: Julien MoutinhoNext: Julien Moutinho
Message 2 of 3 in “gitweb: fix UTF-8 encoding when using CGI::Fast”
  1. gitweb: fix UTF-8 encoding when using CGI::FastJulien Moutinho, Mar 29, 2020
  2. Junio C HamanoMar 29, 2020
  3. Julien MoutinhoMar 29, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.