]> Pileus Git - ~andy/git/commitdiff
gitweb: esc_html_hl_regions(): Don't create empty <span> elements
authorMichał Kiedrowicz <michal.kiedrowicz@gmail.com>
Wed, 11 Apr 2012 21:18:38 +0000 (23:18 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 11 Apr 2012 21:26:01 +0000 (14:26 -0700)
If $end is equal to or less than $begin, esc_html_hl_regions()
generates an empty <span> element.  It normally shouldn't be visible in
the web browser, but it doesn't look good when looking at page source.
It also minimally increases generated page size for no special reason.

Signed-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com>
Acked-by: Jakub Narębski <jnareb@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
gitweb/gitweb.perl

index 1c5430158207bf4b549bd7b95789f70ee0c0a6e0..588b87d234b121b77e5a811ad6a8b55addf16c18 100755 (executable)
@@ -1740,6 +1740,9 @@ sub esc_html_hl_regions {
        for my $s (@sel) {
                my ($begin, $end) = @$s;
 
+               # Don't create empty <span> elements.
+               next if $end <= $begin;
+
                my $escaped = esc_html(substr($str, $begin, $end - $begin));
 
                $out .= esc_html(substr($str, $pos, $begin - $pos))