gitweb: Use character or octal escape codes (and add span.cntrl) in esc_path
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 <jnareb@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
Jakub Narebski committed
Nov 8, 2006 at 11:50 UTC
1d3bc0cc0aaa056ae07a08bccc056e62d42046e8
1 file changed
+29
-1
gitweb/gitweb.perl
+29
-1
@@ -584,11 +584,39 @@ sub esc_html ($;%) {
584
return $str;
585
}
586
587
+# Make control characterss "printable".
588
+sub quot_cec {
589
+ my $cntrl = shift;
590
+ my %es = ( # character escape codes, aka escape sequences
591
+ "\t" => '\t', # tab (HT)
592
+ "\n" => '\n', # line feed (LF)
593
+ "\r" => '\r', # carrige return (CR)
594
+ "\f" => '\f', # form feed (FF)
595
+ "\b" => '\b', # backspace (BS)
596
+ "\a" => '\a', # alarm (bell) (BEL)
597
+ "\e" => '\e', # escape (ESC)
598
+ "\013" => '\v', # vertical tab (VT)
599
+ "\000" => '\0', # nul character (NUL)
600
+ );
601
+ my $chr = ( (exists $es{$cntrl})
602
+ ? $es{$cntrl}
603
+ : sprintf('\%03o', ord($cntrl)) );
604
+ return "<span class=\"cntrl\">$chr</span>";
605
+}
606
+
607
+# Alternatively use unicode control pictures codepoints.
608
+sub quot_upr {
609
+ my $cntrl = shift;
610
+ my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
611
+ return "<span class=\"cntrl\">$chr</span>";
612
+}
613
+
614
# quote control characters and escape filename to HTML
615
sub esc_path {
616
my $str = shift;
617
+
618
$str = esc_html($str);
591
- $str =~ s|([[:cntrl:]])|<span class="cntrl">?</span>|g;
619
+ $str =~ s|([[:cntrl:]])|quot_cec($1)|eg;
620
return $str;
621
}
622