From: Qixing ksyx Xue Date: Wed, 07 Jun 2023 00:00:18 GMT Subject: [PATCH] gitweb: wrong capture group used for grep search Message-ID: The capture group numberings $1, $2, and $3 used in the original script does not work well when the search term itself has capture group, and could be replicated with the simplest case of p(a|b), whose search result with regard to original text `XpaY' would yield `Xpaa' since capture group 3 now becomes the one in the search term, instead of some suffix. This patch fixes the problem with named capture group with capture names that hopefully would not conflict. Signed-off-by: Qixing ksyx Xue --- gitweb/gitweb.perl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index e66eb3d9ba..e868122853 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -6418,12 +6418,12 @@ sub git_search_files { print "
Binary file
\n"; } else { $ltext = untabify($ltext); - if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) { - $ltext = esc_html($1, -nbsp=>1); + if ($ltext =~ m/^(?<__gitweb__prefix>.*)(?<__gitweb__matching_text>$search_regexp)(?<__gitweb__suffix>.*)$/i) { + $ltext = esc_html($+{__gitweb__prefix}, -nbsp=>1); $ltext .= ''; - $ltext .= esc_html($2, -nbsp=>1); + $ltext .= esc_html($+{__gitweb__matching_text}, -nbsp=>1); $ltext .= ''; - $ltext .= esc_html($3, -nbsp=>1); + $ltext .= esc_html($+{__gitweb__suffix}, -nbsp=>1); } else { $ltext = esc_html($ltext, -nbsp=>1); } -- 2.30.0