Skip to content

Commit 9768a9d

Browse files
jnarebgitster
authored andcommitted
gitweb: Pass esc_html_hl_regions() options to esc_html()
With this change, esc_html_hl_regions() accepts options and passes them down to esc_html(). This may be needed if a caller wants to pass -nbsp=>1 to esc_html(). The idea and implementation example of this change was described in 337da8d (gitweb: Introduce esc_html_match_hl and esc_html_hl_regions, 2012-02-27). While other suggestions may be more useful in some cases, there is no need to implement them at the moment. The esc_html_hl_regions() interface may be changed later if it's needed. [mk: extracted from larger patch and wrote commit message] Signed-off-by: Jakub Narębski <[email protected]> Signed-off-by: Michał Kiedrowicz <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cbbea3d commit 9768a9d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

gitweb/gitweb.perl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,7 +1732,9 @@ sub chop_and_escape_str {
17321732
# '<span class="mark">foo</span>bar'
17331733
sub esc_html_hl_regions {
17341734
my ($str, $css_class, @sel) = @_;
1735-
return esc_html($str) unless @sel;
1735+
my %opts = grep { ref($_) ne 'ARRAY' } @sel;
1736+
@sel = grep { ref($_) eq 'ARRAY' } @sel;
1737+
return esc_html($str, %opts) unless @sel;
17361738

17371739
my $out = '';
17381740
my $pos = 0;
@@ -1743,15 +1745,16 @@ sub esc_html_hl_regions {
17431745
# Don't create empty <span> elements.
17441746
next if $end <= $begin;
17451747

1746-
my $escaped = esc_html(substr($str, $begin, $end - $begin));
1748+
my $escaped = esc_html(substr($str, $begin, $end - $begin),
1749+
%opts);
17471750

1748-
$out .= esc_html(substr($str, $pos, $begin - $pos))
1751+
$out .= esc_html(substr($str, $pos, $begin - $pos), %opts)
17491752
if ($begin - $pos > 0);
17501753
$out .= $cgi->span({-class => $css_class}, $escaped);
17511754

17521755
$pos = $end;
17531756
}
1754-
$out .= esc_html(substr($str, $pos))
1757+
$out .= esc_html(substr($str, $pos), %opts)
17551758
if ($pos < length($str));
17561759

17571760
return $out;

0 commit comments

Comments
 (0)