From: Michał Kiedrowicz Date: Wed, 11 Apr 2012 21:18:38 +0000 (+0200) Subject: gitweb: esc_html_hl_regions(): Don't create empty elements X-Git-Url: https://git.ladys.computer/Gitweb/commitdiff_plain/1c065aeeb084074bbebc0b5465f3cb4733c9aae370fb70f290c341ca32d78bdc?ds=inline;hp=3ca8b9c2c0dc5fa4427d6d1c8a41590cdc2bd1097c0e6e5975b2332aafe5ca97 gitweb: esc_html_hl_regions(): Don't create empty elements If $end is equal to or less than $begin, esc_html_hl_regions() generates an empty 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 Acked-by: Jakub Narębski Signed-off-by: Junio C Hamano --- diff --git a/gitweb.perl b/gitweb.perl index e8f277c..91663a4 100755 --- a/gitweb.perl +++ b/gitweb.perl @@ -1741,6 +1741,9 @@ sub esc_html_hl_regions { for my $s (@sel) { my ($begin, $end) = @$s; + # 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))