{"thread":{"id":"59841","subject":"[PATCH] gitweb: wrong capture group used for grep search","startedAt":"2023-06-07T00:01:46Z","lastAt":"2023-07-21T16:39:35Z","messageCount":3,"participants":["Qixing ksyx Xue"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"478119","messageId":"ME2P282MB224200468AFBBBD4534ED1F7B453A@ME2P282MB2242.AUSP282.PROD.OUTLOOK.COM","threadId":"59841","inReplyTo":null,"subject":"[PATCH] gitweb: wrong capture group used for grep search","fromName":"Qixing ksyx Xue","fromEmail":"qixingxue@outlook.com","sentAt":"2023-06-07T00:00:18Z","receivedAt":"2023-06-07T00:01:46Z","isPatch":true,"sender":{"key":"qixingxue@outlook.com","avatar":null},"body":"The capture group numberings $1, $2, and $3 used in the original script\ndoes not work well when the search term itself has capture group, and\ncould be replicated with the simplest case of p(a|b), whose search\nresult with regard to original text `XpaY' would yield `Xpaa' since\ncapture group 3 now becomes the one in the search term, instead of\nsome suffix. This patch fixes the problem with named capture group with\ncapture names that hopefully would not conflict.\n\nSigned-off-by: Qixing ksyx Xue <qixingxue@outlook.com>\n---\n gitweb/gitweb.perl | 8 ++++----\n 1 file changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex e66eb3d9ba..e868122853 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -6418,12 +6418,12 @@ sub git_search_files {\n \t\t\tprint \"<div class=\\\"binary\\\">Binary file</div>\\n\";\n \t\t} else {\n \t\t\t$ltext = untabify($ltext);\n-\t\t\tif ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {\n-\t\t\t\t$ltext = esc_html($1, -nbsp=>1);\n+\t\t\tif ($ltext =~ m/^(?<__gitweb__prefix>.*)(?<__gitweb__matching_text>$search_regexp)(?<__gitweb__suffix>.*)$/i) {\n+\t\t\t\t$ltext = esc_html($+{__gitweb__prefix}, -nbsp=>1);\n \t\t\t\t$ltext .= '<span class=\"match\">';\n-\t\t\t\t$ltext .= esc_html($2, -nbsp=>1);\n+\t\t\t\t$ltext .= esc_html($+{__gitweb__matching_text}, -nbsp=>1);\n \t\t\t\t$ltext .= '</span>';\n-\t\t\t\t$ltext .= esc_html($3, -nbsp=>1);\n+\t\t\t\t$ltext .= esc_html($+{__gitweb__suffix}, -nbsp=>1);\n \t\t\t} else {\n \t\t\t\t$ltext = esc_html($ltext, -nbsp=>1);\n \t\t\t}\n-- \n2.30.0\n\n"},{"id":"479747","messageId":"ME2P282MB2242E63AC1A1AC91E29BF935B43FA@ME2P282MB2242.AUSP282.PROD.OUTLOOK.COM","threadId":"59841","inReplyTo":"ME2P282MB224200468AFBBBD4534ED1F7B453A@ME2P282MB2242.AUSP282.PROD.OUTLOOK.COM","subject":"[PATCH] gitweb: wrong capture group used for grep search","fromName":"Qixing ksyx Xue","fromEmail":"qixingxue@outlook.com","sentAt":"2023-07-21T16:36:04Z","receivedAt":"2023-07-21T16:39:04Z","isPatch":true,"sender":{"key":"qixingxue@outlook.com","avatar":null},"body":"Rebased to master and a polite ping :)\n\nBest,\nQixing\n\n\n"},{"id":"479748","messageId":"ME2P282MB2242C7D0E3D92E2CE5A13B68B43FA@ME2P282MB2242.AUSP282.PROD.OUTLOOK.COM","threadId":"59841","inReplyTo":"ME2P282MB224200468AFBBBD4534ED1F7B453A@ME2P282MB2242.AUSP282.PROD.OUTLOOK.COM","subject":"[PATCH] gitweb: wrong capture group used for grep search","fromName":"Qixing ksyx Xue","fromEmail":"qixingxue@outlook.com","sentAt":"2023-07-21T16:36:05Z","receivedAt":"2023-07-21T16:39:35Z","isPatch":true,"sender":{"key":"qixingxue@outlook.com","avatar":null},"body":"The capture group numberings $1, $2, and $3 used in the original script\ndoes not work well when the search term itself has capture group, and\ncould be replicated with the simplest case of p(a|b), whose search\nresult with regard to original text `XpaY' would yield `Xpaa' since\ncapture group 3 now becomes the one in the search term, instead of\nsome suffix. This patch fixes the problem with named capture group with\ncapture names that hopefully would not conflict.\n\nSigned-off-by: Qixing ksyx Xue <qixingxue@outlook.com>\n---\n gitweb/gitweb.perl | 8 ++++----\n 1 file changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex e66eb3d9ba..e868122853 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -6418,12 +6418,12 @@ sub git_search_files {\n \t\t\tprint \"<div class=\\\"binary\\\">Binary file</div>\\n\";\n \t\t} else {\n \t\t\t$ltext = untabify($ltext);\n-\t\t\tif ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {\n-\t\t\t\t$ltext = esc_html($1, -nbsp=>1);\n+\t\t\tif ($ltext =~ m/^(?<__gitweb__prefix>.*)(?<__gitweb__matching_text>$search_regexp)(?<__gitweb__suffix>.*)$/i) {\n+\t\t\t\t$ltext = esc_html($+{__gitweb__prefix}, -nbsp=>1);\n \t\t\t\t$ltext .= '<span class=\"match\">';\n-\t\t\t\t$ltext .= esc_html($2, -nbsp=>1);\n+\t\t\t\t$ltext .= esc_html($+{__gitweb__matching_text}, -nbsp=>1);\n \t\t\t\t$ltext .= '</span>';\n-\t\t\t\t$ltext .= esc_html($3, -nbsp=>1);\n+\t\t\t\t$ltext .= esc_html($+{__gitweb__suffix}, -nbsp=>1);\n \t\t\t} else {\n \t\t\t\t$ltext = esc_html($ltext, -nbsp=>1);\n \t\t\t}\n-- \n2.30.0\n\n"}]}