@matheusbsbs / matheus-bagliano / commits / 391862e345
Fork 0

gitweb: Do not use esc_html in esc_path

Do not use esc_html in esc_path subroutine to avoid double quoting; expand esc_html body (except quoting) in esc_path. Move esc_path before quot_cec and quot_upr. Add some comments. Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>

Jakub Narebski committed Nov 25, 2006 at 09:43 UTC 391862e34571c0e7e88a5f6e84211b7b8bf55440
1 file changed +17 -11
gitweb/gitweb.perl
+17 -11
@@ -585,7 +585,21 @@ sub esc_html ($;%) {
585 return $str;
586 }
587
588 -# Make control characterss "printable".
588 +# quote control characters and escape filename to HTML
589 +sub esc_path {
590 + my $str = shift;
591 + my %opts = @_;
592 +
593 + $str = to_utf8($str);
594 + $str = escapeHTML($str);
595 + if ($opts{'-nbsp'}) {
596 + $str =~ s/ /&nbsp;/g;
597 + }
598 + $str =~ s|([[:cntrl:]])|quot_cec($1)|eg;
599 + return $str;
600 +}
601 +
602 +# Make control characters "printable", using character escape codes (CEC)
603 sub quot_cec {
604 my $cntrl = shift;
605 my %es = ( # character escape codes, aka escape sequences
@@ -605,22 +619,14 @@ sub quot_cec {
619 return "<span class=\"cntrl\">$chr</span>";
620 }
621
608 -# Alternatively use unicode control pictures codepoints.
622 +# Alternatively use unicode control pictures codepoints,
623 +# Unicode "printable representation" (PR)
624 sub quot_upr {
625 my $cntrl = shift;
626 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
627 return "<span class=\"cntrl\">$chr</span>";
628 }
629
615 -# quote control characters and escape filename to HTML
616 -sub esc_path {
617 - my $str = shift;
618 -
619 - $str = esc_html($str);
620 - $str =~ s|([[:cntrl:]])|quot_cec($1)|eg;
621 - return $str;
622 -}
623 -
630 # git may return quoted and escaped filenames
631 sub unquote {
632 my $str = shift;