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

[PATCH 2/2] gitweb: Use character or octal escape codes (and add span.cntrl) in esc_path

From
Jakub Narebski <jnareb@gmail.com>
Date
Nov 8, 2006, 10:50 UTC
Message-ID
<200611081150.07469.jnareb@gmail.com>
In-Reply-To
<200611081147.52952.jnareb@gmail.com>

Instead of simply hiding control characters in esc_path by replacing them with '?', use Character Escape Codes (CEC) i.e. alphabetic backslash sequences like those found in C programming language and many other languages influenced by it, such as Java and Perl. If control characted doesn't have corresponding character escape code, use octal char sequence to escape it.

Additionally use 'span' element with 'cntrl' attribute to mark escaped control characters. Add style for span.cntrl in the CSS.

Below there is alternative quoting using Unicode Printable Representation (PR), i.e. replace control characters with appropriate Unicode Control Pictures U+2400 - U+243F (9216 - 9279), the Unicode characters reserved for representing control characters when it is necessary to print or display them:

sub esc_path {
	my $str = shift;
	$str = esc_html($str);
	$str =~ s!([[:cntrl:]])!sprintf('<span class="cntrl">&#%04d;</span>', 0x2400+ord($1))!eg;
	return $str;
}
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
The styling (span.cntrl style) isn't best, I agree.
 gitweb/gitweb.css  |    7 +++++++
 gitweb/gitweb.perl |   25 ++++++++++++++++++++++++-
 2 files changed, 31 insertions(+), 1 deletions(-)
diff --git a/gitweb/gitweb.css b/gitweb/gitweb.css
index 0eda982..e19e6bc 100644
--- a/gitweb/gitweb.css
+++ b/gitweb/gitweb.css
@@ -16,6 +16,13 @@ a:hover, a:visited, a:active {
 	color: #880000;
 }
 
+span.cntrl {
+	border: dashed #aaaaaa;
+	border-width: 1px;
+	padding: 0px 2px 0px 2px;
+	margin:  0px 2px 0px 2px;
+}
+
 img.logo {
 	float: right;
 	border-width: 0px;
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 32926f9..c9b16b5 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -587,8 +587,31 @@ sub esc_html ($;%) {
 # quote control characters and escape filename to HTML
 sub esc_path {
 	my $str = shift;
+
+	sub quot {
+		my $seq = shift;
+		my %es = ( # character escape codes, aka escape sequences
+			"\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)
+			"\013" => '\v', # vertical tab   (VT)
+			"\000" => '\0', # null character (NUL)
+		);
+
+		if (exists $es{$seq}) {
+			# C escape sequence, aka character escape code
+			return $es{$seq};
+		}
+		# octal char sequence
+		return sprintf('\%03o', ord($seq));
+	}
+
 	$str = esc_html($str);
-	$str =~ s/[[:cntrl:]]/?/g; # like --hide-control-chars in ls
+	$str =~ s!([[:cntrl:]])!'<span class="cntrl">' . quot($1) . '</span>'!eg;
 	return $str;
 }
 
-- 
1.4.3.4
Previous: Jakub NarebskiNext: Jakub Narebski
Message 3 of 16 in “Better unquoting of git quoted filenames; esc_path to escape pathnames for display”
  1. 0/2 Better unquoting of git quoted filenames; esc_path to escape pathnames for displayJakub Narebski, Nov 8, 2006
  2. 1/2 gitweb: Better git-unquoting and gitweb-quoting of pathnamesJakub Narebski, Nov 8, 2006
  3. 2/2 gitweb: Use character or octal escape codes (and add span.cntrl) in esc_pathJakub Narebski, Nov 8, 2006
  4. 0/2 gitweb: New improved patchset viewJakub Narebski, Nov 8, 2006
  5. 1/2 gitweb: New improved patchset viewJakub Narebski, Nov 8, 2006
  6. Junio C HamanoNov 8, 2006
  7. Junio C HamanoNov 8, 2006
  8. Jakub NarebskiNov 8, 2006
  9. 1/2 gitweb: New improved patchset viewJakub Narebski, Nov 8, 2006
  10. 2/2 gitweb: New improved formatting of chunk header in diffJakub Narebski, Nov 8, 2006
  11. Junio C HamanoNov 8, 2006
  12. Jakub NarebskiNov 8, 2006
  13. Junio C HamanoNov 8, 2006
  14. Jakub NarebskiNov 8, 2006
  15. Junio C HamanoNov 8, 2006
  16. Jakub NarebskiNov 8, 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.