@matheusbsbs / matheus-bagliano / commits / c84c483ffd
Fork 0

gitweb: Add new option -nohtml to quot_xxx subroutines

Add support for new option -nohtml to quot_cec and quot_upr subroutines, to have output not wrapped in HTML tags. This makes those subroutines suitable to quoting attributes values, and for plain text output quoting. Currently this API is not used yet. While at it fix whitespace, and use ';' as delimiter, not separator. The option to not wrap quot_cec output in HTML tag were proposed originally in patch: "Don't open a XML tag while another one is already open" Message-ID: <20080216191628.GK30676@schiele.dyndns.org> by Robert Schiele. Originally the parameter was named '-notag', was also supportted by esc_html (but not esc_path) which passed it down to quot_cec. Mentioned patch was meant to fix the bug Martin Koegler reported in his mail "Invalid html output repo.or.cz (alt-git.git)" Message-ID: <20080216130037.GA14571@auto.tuwien.ac.at> which was fixed in different way (do not use esc_html to escape and quote HTML attributes). Signed-off-by: Robert Schiele <rschiele@gmail.com> Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jakub Narebski committed Feb 17, 2008 at 18:48 UTC c84c483ffdfc45d8143fd6f6620361aba91d1080
1 file changed +24 -13
gitweb/gitweb.perl
+24 -13
@@ -753,29 +753,40 @@ sub esc_path {
753 # Make control characters "printable", using character escape codes (CEC)
754 sub quot_cec {
755 my $cntrl = shift;
756 + my %opts = @_;
757 my %es = ( # character escape codes, aka escape sequences
757 - "\t" => '\t', # tab (HT)
758 - "\n" => '\n', # line feed (LF)
759 - "\r" => '\r', # carrige return (CR)
760 - "\f" => '\f', # form feed (FF)
761 - "\b" => '\b', # backspace (BS)
762 - "\a" => '\a', # alarm (bell) (BEL)
763 - "\e" => '\e', # escape (ESC)
764 - "\013" => '\v', # vertical tab (VT)
765 - "\000" => '\0', # nul character (NUL)
766 - );
758 + "\t" => '\t', # tab (HT)
759 + "\n" => '\n', # line feed (LF)
760 + "\r" => '\r', # carrige return (CR)
761 + "\f" => '\f', # form feed (FF)
762 + "\b" => '\b', # backspace (BS)
763 + "\a" => '\a', # alarm (bell) (BEL)
764 + "\e" => '\e', # escape (ESC)
765 + "\013" => '\v', # vertical tab (VT)
766 + "\000" => '\0', # nul character (NUL)
767 + );
768 my $chr = ( (exists $es{$cntrl})
769 ? $es{$cntrl}
770 : sprintf('\%03o', ord($cntrl)) );
770 - return "<span class=\"cntrl\">$chr</span>";
771 + if ($opts{-nohtml}) {
772 + return $chr;
773 + } else {
774 + return "<span class=\"cntrl\">$chr</span>";
775 + }
776 }
777
778 # Alternatively use unicode control pictures codepoints,
779 # Unicode "printable representation" (PR)
780 sub quot_upr {
781 my $cntrl = shift;
782 + my %opts = @_;
783 +
784 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
778 - return "<span class=\"cntrl\">$chr</span>";
785 + if ($opts{-nohtml}) {
786 + return $chr;
787 + } else {
788 + return "<span class=\"cntrl\">$chr</span>";
789 + }
790 }
791
792 # git may return quoted and escaped filenames
@@ -800,7 +811,7 @@ sub unquote {
811 return chr(oct($seq));
812 } elsif (exists $es{$seq}) {
813 # C escape sequence, aka character escape code
803 - return $es{$seq}
814 + return $es{$seq};
815 }
816 # quoted ordinary character
817 return $seq;