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

Re: [PATCH/RFC 1/n] gitweb: Better git-unquoting and gitweb-quoting of pathnames

From
Junio C Hamano <junkio@cox.net>
Date
Nov 3, 2006, 08:15 UTC
Message-ID
<7vlkmtgd3o.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<200610301958.23334.jnareb@gmail.com>
Jakub Narebski <jnareb@gmail.com> writes:
Show 16 quoted lines
> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
> index ec46b80..a15e916 100755
> --- a/gitweb/gitweb.perl
> +++ b/gitweb/gitweb.perl
> @@ -563,12 +563,42 @@ sub esc_html {
>  	return $str;
>  }
>  
> +# quote unsafe characters and escape filename to HTML
> +sub esc_path {
> +	my $str = shift;
> +	$str = esc_html($str);
> +	$str =~ s/[[:cntrl:]\a\b\e\f\n\r\t\011]/?/g; # like --hide-control-chars in ls
> +	return $str;
> +}
> +
When you say "[:cntrl:]" do you need to say anything more?

I was initially puzzled by "\t\011" bit, but I realize that is a bug that is consistent with the next part I'll comment on.

Show 21 quoted lines
>  # git may return quoted and escaped filenames
>  sub unquote {
>  	my $str = shift;
> +
> +	sub unq {
> +		my $seq = shift;
> +		my %es = (
> +			't' => "\t", # tab            (HT, TAB)
> +			'n' => "\n", # newline        (NL)
> +			'r' => "\r", # return         (CR)
> +			'f' => "\f", # form feed      (FF)
> +			'b' => "\b", # backspace      (BS)
> +			'a' => "\a", # alarm (bell)   (BEL)
> +			#'e' => "\e", # escape        (ESC)
> +			'v' => "\011", # vertical tab (VT)
> +		);
> +
> +		# octal char sequence
> +		return chr(oct($seq))  if ($seq =~ m/^[0-7]{1,3}$/);
> +		# C escape sequence (this includes '\n' (LF) and '\t' (TAB))
> +		return $es{$seq}       if ($seq =~ m/^[abefnrtv]$/);
Problems in this part of the code X-<.
 * Was there a reason not to unwrap '\e' to "\e"?
 * The vertical tab is \013 (decimal 11), not \011 (which is TAB).
 * The name and the abbreviated name of the character "\n" are
   "line feed" and "LF"; I personally do not think these
   character name comments are needed in this part of the code,
   but I do not object if you want to have them there, as long
   as you spell them correctly. cf. ISO/IEC 6429:1992 or
   http://www.unicode.org/charts/PDF/U0000.pdf for example.
 * The hash %es and the pattern /[abef...]/ must be kept in
   sync; it is a maintenance nightmare,
 * Worse yet, they do not agree even in this initial version,
   which proves the previous point.
Perhaps this is better written as:
	if (exists $es{$seq}) {
        	return $es{$seq};
	}

The rest must have been a lot of work to sift through esc_html and identify which is path and which is not. Much appreciated and expect a cleaned up patch to be applied.

Previous: Jakub NarebskiNext: Jakub Narebski
Message 3 of 46 in “gitweb: Better quoting and New improved patchset view”
  1. gitweb: Better quoting and New improved patchset viewJakub Narebski, Oct 30, 2006
  2. gitweb: Better git-unquoting and gitweb-quoting of pathnamesJakub Narebski, Oct 30, 2006
  3. Junio C HamanoNov 3, 2006
  4. Jakub NarebskiNov 3, 2006
  5. Junio C HamanoNov 3, 2006
  6. Jakub NarebskiNov 3, 2006
  7. gitweb: Use '&iquot;' instead of '?' in esc_pathJakub Narebski, Oct 30, 2006
  8. Junio C HamanoOct 31, 2006
  9. Junio C HamanoOct 31, 2006
  10. Jakub NarebskiOct 31, 2006
  11. Jakub NarebskiNov 3, 2006
  12. Junio C HamanoNov 3, 2006
  13. Jakub NarebskiNov 3, 2006
  14. Junio C HamanoNov 3, 2006
  15. Petr BaudisNov 3, 2006
  16. Jakub NarebskiNov 3, 2006
  17. Junio C HamanoNov 4, 2006
  18. Petr BaudisNov 4, 2006
  19. Jakub NarebskiNov 6, 2006
  20. Junio C HamanoNov 6, 2006
  21. Jakub NarebskiNov 6, 2006
  22. Jakub NarebskiNov 7, 2006
  23. Junio C HamanoNov 7, 2006
  24. gitweb: Use 's' regexp modifier to secure against filenames with LFJakub Narebski, Oct 30, 2006
  25. gitweb: Secure against commit-ish/tree-ish with the same name as pathJakub Narebski, Oct 30, 2006
  26. Jakub NarebskiOct 31, 2006
  27. Junio C HamanoNov 1, 2006
  28. Jakub NarebskiNov 1, 2006
  29. Junio C HamanoNov 2, 2006
  30. Jakub NarebskiNov 2, 2006
  31. Junio C HamanoNov 3, 2006
  32. Junio C HamanoNov 3, 2006
  33. Jakub NarebskiNov 3, 2006
  34. [take 3] gitweb: New improved patchset viewJakub Narebski, Oct 31, 2006
  35. 5/10 gitweb: New improved patchset viewJakub Narebski, Nov 3, 2006
  36. gitweb: Remove redundant "blob" links from git_difftree_bodyJakub Narebski, Oct 31, 2006
  37. Junio C HamanoNov 3, 2006
  38. Jakub NarebskiNov 3, 2006
  39. gitweb: Output also empty patches in "commitdiff" viewJakub Narebski, Oct 31, 2006
  40. Jakub NarebskiNov 3, 2006
  41. gitweb: Fix two issues with quoted filenames in git_patchset_bodyJakub Narebski, Oct 31, 2006
  42. gitweb: Better support for non-CSS aware web browsersJakub Narebski, Nov 1, 2006
  43. Petr BaudisNov 1, 2006
  44. gitweb: New improved formatting of chunk header in diffJakub Narebski, Nov 1, 2006
  45. Jakub NarebskiNov 1, 2006
  46. Jakub NarebskiNov 7, 2006

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.