git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] gitweb: highlight: strip non-printable characters via col(1)

From
Jakub Narebski <jnareb@gmail.com>
Date
Aug 26, 2011, 22:06 UTC
Message-ID
<201108270006.19289.jnareb@gmail.com>
In-Reply-To
<7v8vqfdf0l.fsf@alter.siamese.dyndns.org>
On Fri, 26 Aug 2011, Junio C Hamano wrote:
Show 9 quoted lines
> Jakub Narebski <jnareb@gmail.com> writes:
> 
> > Why use external program (which ming be not installed, or might not
> > strip control-characters), instead of making gitweb sanitize highlighter
> > output itself.  Something like the patch below (which additionally
> > shows where there are control characters):
> 
> I agree that that would be a more sensible approach. What does your sample
> code below do to a HT by the way?
Actually the line earlier
 			$line = untabify($line);
replaces HT ("\t") with spaces.
Show 19 quoted lines
> > -- >8 --
> > diff --git i/gitweb/gitweb.perl w/gitweb/gitweb.perl
> > index 7cf12af..192db2c 100755
> > --- i/gitweb/gitweb.perl
> > +++ w/gitweb/gitweb.perl
> > @@ -1517,6 +1517,17 @@ sub esc_path {
> >  	return $str;
> >  }
> >  
> > +# Sanitize for use in XHTML + application/xml+xhtml
> > +sub sanitize {
> > +	my $str = shift;
> > +
> > +	return undef unless defined $str;
> > +
> > +	$str = to_utf8($str);
> > +	$str =~ s|([[:cntrl:]])|quot_cec($1)|eg;
> > +	return $str;
> > +}
Anyway, it could well be

+ $str =~ s|([[:cntrl:]])|(($1 ne "\t") ? quot_cec($1) : $1)|eg; + return $str;

like in esc_html rather than like in esc_path.
> > @@ -6546,7 +6557,8 @@ sub git_blob {
> >  			$nr++;
> >  			$line = untabify($line);
                        ^^^^^^^^^^^^^^^^^^^^^^^^
Show 7 quoted lines
> >  			printf qq!<div class="pre"><a id="l%i" href="%s#l%i" class="linenr">%4i</a> %s</div>\n!,
> > -			       $nr, esc_attr(href(-replay => 1)), $nr, $nr, $syntax ? to_utf8($line) : esc_html($line, -nbsp=>1);
> > +			       $nr, esc_attr(href(-replay => 1)), $nr, $nr,
> > +			       $syntax ? sanitize($line) : esc_html($line, -nbsp=>1);
> >  		}
> >  	}
> >  	close $fd
-- 
Jakub Narebski
Poland
Previous: Junio C HamanoNext: Jakub Narebski
Message 5 of 10 in “gitweb: highlight: strip non-printable characters via col(1)”
  1. gitweb: highlight: strip non-printable characters via col(1)Christopher M. Fuhrman, Aug 22, 2011
  2. Junio C HamanoAug 22, 2011
  3. Jakub NarebskiAug 26, 2011
  4. Junio C HamanoAug 26, 2011
  5. Jakub NarebskiAug 26, 2011
  6. gitweb: Strip non-printable characters from syntax highlighter outputJakub Narebski, Sep 16, 2011
  7. Junio C HamanoSep 16, 2011
  8. Jakub NarebskiSep 16, 2011
  9. Junio C HamanoSep 16, 2011
  10. Christopher M. FuhrmanSep 16, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.