]> Lady’s Gitweb - Gitweb/commitdiff
gitweb: Use character or octal escape codes (and add span.cntrl) in esc_path
authorJakub Narebski <redacted>
Wed, 8 Nov 2006 10:50:07 +0000 (11:50 +0100)
committerLady <redacted>
Mon, 6 Apr 2026 04:07:11 +0000 (00:07 -0400)
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.

Alternatively, controls can be replaced with 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.

Signed-off-by: Jakub Narebski <redacted>
Signed-off-by: Junio C Hamano <redacted>
gitweb.perl

index 4591ed7150de2f0e27c4a950d79ab5cce06414a39b1eefc42c334777ad1ff156..39a19585d1974765364364e86ede74f33be54349de3b709b3ad3981cb851270f 100755 (executable)
@@ -585,11 +585,39 @@ sub esc_html ($;%) {
        return $str;
 }
 
+# Make control characterss "printable".
+sub quot_cec {
+       my $cntrl = shift;
+       my %es = ( # character escape codes, aka escape sequences
+                  "\t" => '\t',   # tab            (HT)
+                  "\n" => '\n',   # line feed      (LF)
+                  "\r" => '\r',   # carrige 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', # nul character  (NUL)
+                  );
+       my $chr = ( (exists $es{$cntrl})
+                   ? $es{$cntrl}
+                   : sprintf('\%03o', ord($cntrl)) );
+       return "<span class=\"cntrl\">$chr</span>";
+}
+
+# Alternatively use unicode control pictures codepoints.
+sub quot_upr {
+       my $cntrl = shift;
+       my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
+       return "<span class=\"cntrl\">$chr</span>";
+}
+
 # quote control characters and escape filename to HTML
 sub esc_path {
        my $str = shift;
+
        $str = esc_html($str);
-       $str =~ s|([[:cntrl:]])|<span class="cntrl">?</span>|g;
+       $str =~ s|([[:cntrl:]])|quot_cec($1)|eg;
        return $str;
 }
 
This page took 0.268992 seconds and 4 git commands to generate.