X-Git-Url: https://git.ladys.computer/Gitweb/blobdiff_plain/32be0fe6462f8e3186fbb2a3e5f3b10189d47cde1dd79a51ade9622241a8e6a4..1c065aeeb084074bbebc0b5465f3cb4733c9aae370fb70f290c341ca32d78bdc:/gitweb.perl diff --git a/gitweb.perl b/gitweb.perl index 144b968..91663a4 100755 --- a/gitweb.perl +++ b/gitweb.perl @@ -1739,12 +1739,18 @@ sub esc_html_hl_regions { my $pos = 0; for my $s (@sel) { - $out .= esc_html(substr($str, $pos, $s->[0] - $pos)) - if ($s->[0] - $pos > 0); - $out .= $cgi->span({-class => $css_class}, - esc_html(substr($str, $s->[0], $s->[1] - $s->[0]))); + my ($begin, $end) = @$s; - $pos = $s->[1]; + # Don't create empty elements. + next if $end <= $begin; + + my $escaped = esc_html(substr($str, $begin, $end - $begin)); + + $out .= esc_html(substr($str, $pos, $begin - $pos)) + if ($begin - $pos > 0); + $out .= $cgi->span({-class => $css_class}, $escaped); + + $pos = $end; } $out .= esc_html(substr($str, $pos)) if ($pos < length($str));