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

[PATCH] gitweb: fix esc_param

From
Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
Date
Oct 13, 2009, 19:51 UTC
Message-ID
<1255463496-21617-1-git-send-email-giuseppe.bilotta@gmail.com>

The custom CGI escaping done in esc_param failed to escape UTF-8 properly. Fix by using CGI::escape on each sequence of matched characters instead of sprintf()ing a custom escaping for each byte.

Additionally, the space -> + escape was being escaped due to greedy matching on the first substitution. Fix by adding space to the list of characters not handled on the first substitution.

Finally, remove an unnecessary escaping of the + sign.
---
 gitweb/gitweb.perl |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

The issues with this routine were exposed by Stephen's "author as search link" patch. This should fix them.

Since the idea of esc_param is to replicate CGI::escape except for the / character (if I read the comment correclty), a possible alternative would be to just use CGI::escape on the whole string and then undo the escaping for the / character.

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 6237865..6593e5c 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -1115,8 +1115,7 @@ sub to_utf8 {
 # correct, but quoted slashes look too horrible in bookmarks
 sub esc_param {
 	my $str = shift;
-	$str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf("%%%02X", ord($1))/eg;
-	$str =~ s/\+/%2B/g;
+	$str =~ s/([^A-Za-z0-9\-_.~()\/:@ ]+)/CGI::escape($1)/eg;
 	$str =~ s/ /\+/g;
 	return $str;
 }
-- 
1.6.3.rc1.192.gdbfcb
Next: Stephen Boyd
Message 1 of 7 in “gitweb: fix esc_param”
  1. gitweb: fix esc_paramGiuseppe Bilotta, Oct 13, 2009
  2. Stephen BoydOct 14, 2009
  3. Giuseppe BilottaOct 14, 2009
  4. Stephen BoydOct 14, 2009
  5. Jakub NarebskiOct 14, 2009
  6. Jakub NarebskiOct 14, 2009
  7. Junio C HamanoOct 14, 2009

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.