diff options
author | Jakub Narebski <jnareb@gmail.com> | 2006-11-08 11:50:07 +0100 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2006-11-08 12:34:03 -0800 |
commit | 1d3bc0cc0aaa056ae07a08bccc056e62d42046e8 (patch) | |
tree | 3bc14a44ce51620afca58c1e520dc9b85515029c | |
parent | 403d0906e9876871a7913554be4caa93f21f1d15 (diff) | |
download | git-1d3bc0cc0aaa056ae07a08bccc056e62d42046e8.tar.gz |
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>
-rwxr-xr-x | gitweb/gitweb.perl | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index fcf255def9..b80fc6070b 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -584,11 +584,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; } |