Skip to content

Commit 25f745f

Browse files
committed
Merge branch 'jn/gitweb-highlite-sanitise' into maint
* jn/gitweb-highlite-sanitise: gitweb: Strip non-printable characters from syntax highlighter output
2 parents 60f60b4 + 0866786 commit 25f745f

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

gitweb/gitweb.perl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1517,6 +1517,17 @@ sub esc_path {
15171517
return $str;
15181518
}
15191519

1520+
# Sanitize for use in XHTML + application/xml+xhtm (valid XML 1.0)
1521+
sub sanitize {
1522+
my $str = shift;
1523+
1524+
return undef unless defined $str;
1525+
1526+
$str = to_utf8($str);
1527+
$str =~ s|([[:cntrl:]])|($1 =~ /[\t\n\r]/ ? $1 : quot_cec($1))|eg;
1528+
return $str;
1529+
}
1530+
15201531
# Make control characters "printable", using character escape codes (CEC)
15211532
sub quot_cec {
15221533
my $cntrl = shift;
@@ -6484,7 +6495,8 @@ sub git_blob {
64846495
$nr++;
64856496
$line = untabify($line);
64866497
printf qq!<div class="pre"><a id="l%i" href="%s#l%i" class="linenr">%4i</a> %s</div>\n!,
6487-
$nr, esc_attr(href(-replay => 1)), $nr, $nr, $syntax ? to_utf8($line) : esc_html($line, -nbsp=>1);
6498+
$nr, esc_attr(href(-replay => 1)), $nr, $nr,
6499+
$syntax ? sanitize($line) : esc_html($line, -nbsp=>1);
64886500
}
64896501
}
64906502
close $fd

0 commit comments

Comments
 (0)