Skip to contentSkip to conversation

gitweb: Handle invalid regexp in regexp search

PATCH In review Jakub Narebski 3 participants 18 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gitweb: Handle invalid regexp in regexp search

When using regexp search ('sr' parameter / $search_use_regexp variable is true), check first that regexp is valid.

Without this patch we would get an error from Perl during search (if searching is performed by gitweb), or highlighting matches substring (if applicable), if user provided invalid regexp... which means broken HTML, with error page (including HTTP headers) generated after gitweb already produced some output.

Add test that illustrates such error: for example for regexp "*\.git" we would get the following error:

Quantifier follows nothing in regex; marked by <-- HERE in m/* <-- HERE \.git/ at /var/www/cgi-bin/gitweb.cgi line 3084.

---
See "Re: gitweb: (potential) problems with new installation"
http://thread.gmane.org/gmane.comp.version-control.git/191746

 gitweb/gitweb.perl                       |   11 ++++++++++-
 t/t9501-gitweb-standalone-http-status.sh |   10 ++++++++++
 2 files changed, 20 insertions(+), 1 deletions(-)
gitweb/gitweb.perl +10 -1
index 1fc5361..22ad279 100755
@@ -1081,7 +1081,16 @@ sub evaluate_and_validate_params {
 		if (length($searchtext) < 2) {
 			die_error(403, "At least two characters are required for search parameter");
 		}
-		$search_regexp = $search_use_regexp ? $searchtext : quotemeta $searchtext;
+		if ($search_use_regexp) {
+			$search_regexp = $searchtext;
+			if (!eval { qr/$search_regexp/; 1; }) {
+				(my $error = $@) =~ s/ at \S+ line \d+.*\n?//;
+				die_error(400, "Invalid search regexp '$search_regexp'",
+				          esc_html($error));
+			}
+		} else {
+			$search_regexp = quotemeta $searchtext;
+		}
 	}
 }
 
t/t9501-gitweb-standalone-http-status.sh +10 -0
index 26102ee..31076ed 100755
@@ -134,4 +134,14 @@ our $maxload = undef;
 EOF
 
 
+# ----------------------------------------------------------------------
+# invalid arguments
+
+test_expect_success 'invalid arguments: invalid regexp (in project search)' '
+	gitweb_run "a=project_list;s=*\.git;sr=1" &&
+	grep "Status: 400" gitweb.headers &&
+	grep "400 - Invalid.*regexp" gitweb.body
+'
+test_debug 'cat gitweb.headers'
+
 test_done
#1 lore raw
Quoted 2 lines · Jakub Narebski

When using regexp search ('sr' parameter / $search_use_regexp variable is true), check first that regexp is valid.

Thanks.

How old is this bug? Should it go to older maitenance tracks like 1.7.6?

#2 lore raw
Quoted 10 lines · Junio C Hamano
Quoted 2 lines · Jakub Narebski

When using regexp search ('sr' parameter / $search_use_regexp variable is true), check first that regexp is valid.

Thanks.

How old is this bug? Should it go to older maitenance tracks like 1.7.6?

From what I examined this bug is from the very beginning when gitweb

started to distinguish regexp search and fixed string search in

0e55991 (gitweb: Clearly distinguish regexp / exact match searches, 2008-02-26)

It was present in 1.5.5 (including beginnings of match highlighting, which trigger this bug).

This bug was present so long without detection because circumstances must be quite specific: you have to select regexp search, and to provide invalid regexp. If you know what regexp is, you probably write correct ones... but there always room for mistake.

Signature · 2 lines
Jakub Narebski
Poland
#3 lore raw
In reply to Jakub Narebski
Quoted 12 lines · Jakub Narebski

When using regexp search ('sr' parameter / $search_use_regexp variable is true), check first that regexp is valid.

Without this patch we would get an error from Perl during search (if searching is performed by gitweb), or highlighting matches substring (if applicable), if user provided invalid regexp... which means broken HTML, with error page (including HTTP headers) generated after gitweb already produced some output.

Add test that illustrates such error: for example for regexp "*\.git" we would get the following error:

Quoted 8 lines

Quantifier follows nothing in regex; marked by <-- HERE in m/* <-- HERE \.git/ at /var/www/cgi-bin/gitweb.cgi line 3084.

---
See "Re: gitweb: (potential) problems with new installation"
http://thread.gmane.org/gmane.comp.version-control.git/191746

This patch solves the problem for me when using a regex search (re checkbox checked), but *not* for a non-regex search.

If you have a leading '*' or '+', in the non-regex case, then you still get the above complaint (and xml error page etc.), although the line number has changed slightly from that given above.

ATB,
Ramsay Jones

#4 lore raw

PATCH 1/1 gitweb: Fix fixed string (non-regexp) project search

Use $search_regexp, where regex metacharacters are quoted, for searching projects list, rather than $searchtext, which contains original search term.

---
I think this bug was here from the very beginning of adding project search, i.e. from v1.6.0.2-446-g0d1d154 (gitweb: Support for simple project search form, 2008-10-03) which was present since 1.6.1

Quoted 23 lines · Ramsay Jones
Quoted 12 lines · Jakub Narebski

When using regexp search ('sr' parameter / $search_use_regexp variable is true), check first that regexp is valid.

Without this patch we would get an error from Perl during search (if searching is performed by gitweb), or highlighting matches substring (if applicable), if user provided invalid regexp... which means broken HTML, with error page (including HTTP headers) generated after gitweb already produced some output.

Add test that illustrates such error: for example for regexp "*\.git" we would get the following error:

Quoted 8 lines

Quantifier follows nothing in regex; marked by <-- HERE in m/* <-- HERE \.git/ at /var/www/cgi-bin/gitweb.cgi line 3084.

---
See "Re: gitweb: (potential) problems with new installation"
http://thread.gmane.org/gmane.comp.version-control.git/191746

Quoted 6 lines

This patch solves the problem for me when using a regex search (re checkbox checked), but *not* for a non-regex search.

If you have a leading '*' or '+', in the non-regex case, then you still get the above complaint (and xml error page etc.), although the line number has changed slightly from that given above.

Ramsay, please provide those line number in the future, together with line and if possible some context.

The line is different because it is different bug: this is about not using quotemeta'ed string for search for fixed-string search.

 gitweb/gitweb.perl |   22 +++++++++++-----------
 1 files changed, 11 insertions(+), 11 deletions(-)
gitweb/gitweb.perl +11 -11
index 22ad279..7398be1 100755
@@ -3072,16 +3072,16 @@ sub filter_forks_from_projects_list {
 # for 'descr_long' and 'ctags' to be filled
 sub search_projects_list {
 	my ($projlist, %opts) = @_;
-	my $tagfilter  = $opts{'tagfilter'};
-	my $searchtext = $opts{'searchtext'};
+	my $tagfilter = $opts{'tagfilter'};
+	my $search_re = $opts{'search_regexp'};
 
 	return @$projlist
-		unless ($tagfilter || $searchtext);
+		unless ($tagfilter || $search_re);
 
 	# searching projects require filling to be run before it;
 	fill_project_list_info($projlist,
-	                       $tagfilter  ? 'ctags' : (),
-	                       $searchtext ? ('path', 'descr') : ());
+	                       $tagfilter ? 'ctags' : (),
+	                       $search_re ? ('path', 'descr') : ());
 	my @projects;
  PROJECT:
 	foreach my $pr (@$projlist) {
@@ -3092,10 +3092,10 @@ sub search_projects_list {
 				grep { lc($_) eq lc($tagfilter) } keys %{$pr->{'ctags'}};
 		}
 
-		if ($searchtext) {
+		if ($search_re) {
 			next unless
-				$pr->{'path'} =~ /$searchtext/ ||
-				$pr->{'descr_long'} =~ /$searchtext/;
+				$pr->{'path'} =~ /$search_re/ ||
+				$pr->{'descr_long'} =~ /$search_re/;
 		}
 
 		push @projects, $pr;
@@ -5498,9 +5498,9 @@ sub git_project_list_body {
 		if ($check_forks);
 	# search_projects_list pre-fills required info
 	@projects = search_projects_list(\@projects,
-	                                 'searchtext' => $searchtext,
-	                                 'tagfilter'  => $tagfilter)
-		if ($tagfilter || $searchtext);
+	                                 'search_regexp' => $search_regexp,
+	                                 'tagfilter' => $tagfilter)
+		if ($tagfilter || $search_regexp);
 	# fill the rest
 	@projects = fill_project_list_info(\@projects);
 
Signature · 1 line
1.7.9
#5 lore raw

Re: [PATCH (BUGFIX)] gitweb: Fix fixed string (non-regexp) project search

Quoted 4 lines · Jakub Narebski

Use $search_regexp, where regex metacharacters are quoted, for searching projects list, rather than $searchtext, which contains original search term.

Quoted 12 lines

---
I think this bug was here from the very beginning of adding project search, i.e. from v1.6.0.2-446-g0d1d154 (gitweb: Support for simple project search form, 2008-10-03) which was present since 1.6.1

Quoted 3 lines · Ramsay Jones

This patch solves the problem for me when using a regex search (re checkbox checked), but *not* for a non-regex search.

This patch depends on the more recent changes than the regexp fix, no? I was hoping that we could merge the earlier fix for the regexp case to older maintenance tracks later, but if we were going to do so, we would want to do the same for a fix for fixed-string case.

I am fine with not to worrying too much about older maintenance tracks, and applying this directly to 'master', but just wanted to see what your preference is.

Thanks.

Quoted 65 lines
Quoted 3 lines

If you have a leading '*' or '+', in the non-regex case, then you still get the above complaint (and xml error page etc.), although the line number has changed slightly from that given above.

Ramsay, please provide those line number in the future, together with line and if possible some context.

The line is different because it is different bug: this is about not using quotemeta'ed string for search for fixed-string search.

 gitweb/gitweb.perl |   22 +++++++++++-----------
 1 files changed, 11 insertions(+), 11 deletions(-)
gitweb/gitweb.perl +11 -11
index 22ad279..7398be1 100755
@@ -3072,16 +3072,16 @@ sub filter_forks_from_projects_list {
 # for 'descr_long' and 'ctags' to be filled
 sub search_projects_list {
 	my ($projlist, %opts) = @_;
-	my $tagfilter  = $opts{'tagfilter'};
-	my $searchtext = $opts{'searchtext'};
+	my $tagfilter = $opts{'tagfilter'};
+	my $search_re = $opts{'search_regexp'};
 
 	return @$projlist
-		unless ($tagfilter || $searchtext);
+		unless ($tagfilter || $search_re);
 
 	# searching projects require filling to be run before it;
 	fill_project_list_info($projlist,
-	                       $tagfilter  ? 'ctags' : (),
-	                       $searchtext ? ('path', 'descr') : ());
+	                       $tagfilter ? 'ctags' : (),
+	                       $search_re ? ('path', 'descr') : ());
 	my @projects;
  PROJECT:
 	foreach my $pr (@$projlist) {
@@ -3092,10 +3092,10 @@ sub search_projects_list {
 				grep { lc($_) eq lc($tagfilter) } keys %{$pr->{'ctags'}};
 		}
 
-		if ($searchtext) {
+		if ($search_re) {
 			next unless
-				$pr->{'path'} =~ /$searchtext/ ||
-				$pr->{'descr_long'} =~ /$searchtext/;
+				$pr->{'path'} =~ /$search_re/ ||
+				$pr->{'descr_long'} =~ /$search_re/;
 		}
 
 		push @projects, $pr;
@@ -5498,9 +5498,9 @@ sub git_project_list_body {
 		if ($check_forks);
 	# search_projects_list pre-fills required info
 	@projects = search_projects_list(\@projects,
-	                                 'searchtext' => $searchtext,
-	                                 'tagfilter'  => $tagfilter)
-		if ($tagfilter || $searchtext);
+	                                 'search_regexp' => $search_regexp,
+	                                 'tagfilter' => $tagfilter)
+		if ($tagfilter || $search_regexp);
 	# fill the rest
 	@projects = fill_project_list_info(\@projects);
#6 lore raw

Re: [PATCH (BUGFIX)] gitweb: Fix fixed string (non-regexp) project search

Quoted 15 lines · Junio C Hamano
Quoted 13 lines · Jakub Narebski

Use $search_regexp, where regex metacharacters are quoted, for searching projects list, rather than $searchtext, which contains original search term.

---
I think this bug was here from the very beginning of adding project search, i.e. from v1.6.0.2-446-g0d1d154 (gitweb: Support for simple project search form, 2008-10-03) which was present since 1.6.1

On Fri, 2 Mar 2012, Ramsay Jones wrote:

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

This patch solves the problem for me when using a regex search (re checkbox checked), but *not* for a non-regex search.

This patch depends on the more recent changes than the regexp fix, no? I was hoping that we could merge the earlier fix for the regexp case to older maintenance tracks later, but if we were going to do so, we would want to do the same for a fix for fixed-string case.

The regexp and non-regexp bugs and fixes are different.

The regexp "bug" was just us forgetting that regexp is provided by user input, and should be validated. The bug as reported by Ramsay was here from the very beginning, i.e. commit 0e55991 (gitweb: Clearly distinguish regexp / exact match searches, 2008-02-26), which was present in v1.5.1 if I have checked correctly. The fix is about adding new code and should apply cleanly to 'maint' and even to older versions; the only trouble with older version might be whitespace issue related to refactoring code into subroutines.

The non-regexp project search bug was using $searchtext instead of $search_regexp as search regexp in gitweb. The bug was present from the very addition of project search, namely commit 0d1d154 (gitweb:
Support for simple project search form, 2008-10-03), which was present in v1.5.1 if I have checked correctly. Unfortunately the fix affects code that was changed recently in a1e1b2d (gitweb: improve usability of projects search form, 2012-01-31); I'll try to come up with equivalent patch to 'maint' soon (if the current one does not apply, and I guess it doesn't).

Signature · 2 lines
Jakub Narebski
Poland
#7 lore raw

PATCH 1/1 gitweb: Fix fixed string (non-regexp) project search

Quoted 26 lines · Jakub Narebski
Quoted 15 lines · Junio C Hamano
Quoted 13 lines · Jakub Narebski

Use $search_regexp, where regex metacharacters are quoted, for searching projects list, rather than $searchtext, which contains original search term.

---
I think this bug was here from the very beginning of adding project search, i.e. from v1.6.0.2-446-g0d1d154 (gitweb: Support for simple project search form, 2008-10-03) which was present since 1.6.1

On Fri, 2 Mar 2012, Ramsay Jones wrote:

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

This patch solves the problem for me when using a regex search (re checkbox checked), but *not* for a non-regex search.

This patch depends on the more recent changes than the regexp fix, no? I was hoping that we could merge the earlier fix for the regexp case to older maintenance tracks later, but if we were going to do so, we would want to do the same for a fix for fixed-string case.

The regexp and non-regexp bugs and fixes are different.

[...]

Quoted 9 lines

The non-regexp project search bug was using $searchtext instead of $search_regexp as search regexp in gitweb. The bug was present from the very addition of project search, namely commit 0d1d154 (gitweb:
Support for simple project search form, 2008-10-03), which was present in v1.5.1 if I have checked correctly. Unfortunately the fix affects code that was changed recently in a1e1b2d (gitweb: improve usability of projects search form, 2012-01-31); I'll try to come up with equivalent patch to 'maint' soon (if the current one does not apply, and I guess it doesn't).

And here is the patch for maint
-->8-- -------------------------------------------------------- -->8--
Subject: gitweb: Fix fixed string (non-regexp) project search

Use $search_regexp, where regex metacharacters are quoted, for searching projects list, rather than $searchtext, which contains original search term.

---
 gitweb/gitweb.perl |   20 +++++++++++---------
 1 files changed, 11 insertions(+), 9 deletions(-)
gitweb/gitweb.perl +11 -9
index d5dbd64..e248792 100755
@@ -2968,11 +2968,11 @@ sub filter_forks_from_projects_list {
 # for 'descr_long' and 'ctags' to be filled
 sub search_projects_list {
 	my ($projlist, %opts) = @_;
-	my $tagfilter  = $opts{'tagfilter'};
-	my $searchtext = $opts{'searchtext'};
+	my $tagfilter = $opts{'tagfilter'};
+	my $search_re = $opts{'search_regexp'};
 
 	return @$projlist
-		unless ($tagfilter || $searchtext);
+		unless ($tagfilter || $search_re);
 
 	my @projects;
  PROJECT:
@@ -2984,10 +2984,10 @@ sub search_projects_list {
 				grep { lc($_) eq lc($tagfilter) } keys %{$pr->{'ctags'}};
 		}
 
-		if ($searchtext) {
+		if ($search_re) {
 			next unless
-				$pr->{'path'} =~ /$searchtext/ ||
-				$pr->{'descr_long'} =~ /$searchtext/;
+				$pr->{'path'} =~ /$search_re/ ||
+				$pr->{'descr_long'} =~ /$search_re/;
 		}
 
 		push @projects, $pr;
@@ -5290,9 +5290,11 @@ sub git_project_list_body {
 	@projects = fill_project_list_info(\@projects);
 	# searching projects require filling to be run before it
 	@projects = search_projects_list(\@projects,
-	                                 'searchtext' => $searchtext,
-	                                 'tagfilter'  => $tagfilter)
-		if ($tagfilter || $searchtext);
+	                                 'search_regexp' => $search_regexp,
+	                                 'tagfilter' => $tagfilter)
+		if ($tagfilter || $search_regexp);
+	# fill the rest
+	@projects = fill_project_list_info(\@projects);
 
 	$order ||= $default_projects_order;
 	$from = 0 unless defined $from;
Signature · 1 line
1.7.9
#8 lore raw

Re: [PATCH (for maint)] gitweb: Fix fixed string (non-regexp) project search

Quoted 20 lines · Jakub Narebski

And here is the patch for maint
-->8-- -------------------------------------------------------- -->8--
Subject: gitweb: Fix fixed string (non-regexp) project search

Use $search_regexp, where regex metacharacters are quoted, for searching projects list, rather than $searchtext, which contains original search term.

---
 gitweb/gitweb.perl |   20 +++++++++++---------
 1 files changed, 11 insertions(+), 9 deletions(-)
gitweb/gitweb.perl +0 -0
index d5dbd64..e248792 100755
@@ -5290,9 +5290,11 @@ sub git_project_list_body {
 	@projects = fill_project_list_info(\@projects);

gitweb/gitweb.perl sub git_project_list_body { · line 5297

Quoted 10 lines
gitweb/gitweb.perl +5 -3
 	# searching projects require filling to be run before it
 	@projects = search_projects_list(\@projects,
-	                                 'searchtext' => $searchtext,
-	                                 'tagfilter'  => $tagfilter)
-		if ($tagfilter || $searchtext);
+	                                 'search_regexp' => $search_regexp,
+	                                 'tagfilter' => $tagfilter)
+		if ($tagfilter || $search_regexp);
+	# fill the rest
+	@projects = fill_project_list_info(\@projects);

Hmph, didn't you already call fill_project_list_info(\@projects) before search_projects_list() already?

#9 lore raw

Re: [PATCH (for maint)] gitweb: Fix fixed string (non-regexp) project search

Quoted 27 lines · Junio C Hamano
Quoted 25 lines · Jakub Narebski

And here is the patch for maint
-->8-- -------------------------------------------------------- -->8--
Subject: gitweb: Fix fixed string (non-regexp) project search

Use $search_regexp, where regex metacharacters are quoted, for searching projects list, rather than $searchtext, which contains original search term.

---
 gitweb/gitweb.perl |   20 +++++++++++---------
 1 files changed, 11 insertions(+), 9 deletions(-)
gitweb/gitweb.perl +0 -3
index d5dbd64..e248792 100755
@@ -5290,9 +5290,11 @@ sub git_project_list_body {
 	@projects = fill_project_list_info(\@projects);
 	# searching projects require filling to be run before it
 	@projects = search_projects_list(\@projects,
-	                                 'searchtext' => $searchtext,
-	                                 'tagfilter'  => $tagfilter)
-		if ($tagfilter || $searchtext);
Quoted 8 lines

gitweb/gitweb.perl sub git_project_list_body { · line 5297

Quoted 5 lines
gitweb/gitweb.perl +5 -0
+	                                 'search_regexp' => $search_regexp,
+	                                 'tagfilter' => $tagfilter)
+		if ($tagfilter || $search_regexp);
+	# fill the rest
+	@projects = fill_project_list_info(\@projects);

Hmph, didn't you already call fill_project_list_info(\@projects) before search_projects_list() already?

True. Sorry about that.

Can you fix that, or should I resend?

Signature · 2 lines
Jakub Narebski
Poland
#10 lore raw

Re: [PATCH (for maint)] gitweb: Fix fixed string (non-regexp) project search

Quoted 12 lines · Jakub Narebski
Quoted 10 lines · Junio C Hamano
Quoted 1 line · Jakub Narebski

And here is the patch for maint

...

gitweb/gitweb.perl sub git_project_list_body { · line 5297

Quoted 3 lines
gitweb/gitweb.perl +3 -0
+		if ($tagfilter || $search_regexp);
+	# fill the rest
+	@projects = fill_project_list_info(\@projects);

Hmph, didn't you already call fill_project_list_info(\@projects) before search_projects_list() already?

Quoted 3 lines

True. Sorry about that.

Can you fix that, or should I resend?

Could you check the following two diffs?

$ git show debd1c2

This is jn/maint-do-not-match-with-unsanitized-searchtext that should be merged to maintenance track that lack the lazy filling.

And then

$ git show --first-parent d4b52c2

This is how the above was merged to 'pu' and the conflict resolution should be the same when we merge it to 'master'. As our @projects may still be only sparsely filled when search_projects_list() returns, we do call fill_project_list_info(\@projects) ourselves with the lazy filling codebase.

There are a few places I noticed that check $searchtext to see if we are running a search, and techinically $search_regexp might be a more correct thing to use, but I do not think it matters that much.

Thanks.

#11 lore raw

Re: [PATCH (for maint)] gitweb: Fix fixed string (non-regexp) project search

Quoted 18 lines · Junio C Hamano
Quoted 6 lines · Jakub Narebski
Quoted 2 lines

Hmph, didn't you already call fill_project_list_info(\@projects) before search_projects_list() already?

True. Sorry about that.

Can you fix that, or should I resend?

Could you check the following two diffs?

$ git show debd1c2

This is jn/maint-do-not-match-with-unsanitized-searchtext that should be merged to maintenance track that lack the lazy filling.

And then

Quoted 7 lines
$ git show --first-parent d4b52c2

This is how the above was merged to 'pu' and the conflict resolution should be the same when we merge it to 'master'. As our @projects may still be only sparsely filled when search_projects_list() returns, we do call fill_project_list_info(\@projects) ourselves with the lazy filling codebase.

The latter is now

$ git show --first-parent 657c6d0

on today's 'pu'.

Thanks.

#12 lore raw

Re: [PATCH (for maint)] gitweb: Fix fixed string (non-regexp) project search

Quoted 27 lines · Junio C Hamano
Quoted 18 lines · Junio C Hamano
Quoted 6 lines · Jakub Narebski
Quoted 2 lines

Hmph, didn't you already call fill_project_list_info(\@projects) before search_projects_list() already?

True. Sorry about that.

Can you fix that, or should I resend?

Could you check the following two diffs?

$ git show debd1c2

This is jn/maint-do-not-match-with-unsanitized-searchtext that should be merged to maintenance track that lack the lazy filling.

And then

Quoted 7 lines
$ git show --first-parent d4b52c2

This is how the above was merged to 'pu' and the conflict resolution should be the same when we merge it to 'master'. As our @projects may still be only sparsely filled when search_projects_list() returns, we do call fill_project_list_info(\@projects) ourselves with the lazy filling codebase.

Quoted 7 lines

The latter is now

$ git show --first-parent 657c6d0

on today's 'pu'.

Thanks.

Both look all right (the only difference in diff is use of $searchtext vs $search_regexp global variable to check if search is on, but for that purpose those variables are equivalent).

Thanks.

Signature · 2 lines
Jakub Narebski
Poland
#13 lore raw

Re: [PATCH (BUGFIX)] gitweb: Fix fixed string (non-regexp) project search

In reply to Jakub Narebski
Quoted 36 lines · Jakub Narebski
Quoted 15 lines · Junio C Hamano
Quoted 13 lines · Jakub Narebski

Use $search_regexp, where regex metacharacters are quoted, for searching projects list, rather than $searchtext, which contains original search term.

---
I think this bug was here from the very beginning of adding project search, i.e. from v1.6.0.2-446-g0d1d154 (gitweb: Support for simple project search form, 2008-10-03) which was present since 1.6.1

On Fri, 2 Mar 2012, Ramsay Jones wrote:

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

This patch solves the problem for me when using a regex search (re checkbox checked), but *not* for a non-regex search.

This patch depends on the more recent changes than the regexp fix, no? I was hoping that we could merge the earlier fix for the regexp case to older maintenance tracks later, but if we were going to do so, we would want to do the same for a fix for fixed-string case.

The regexp and non-regexp bugs and fixes are different.

The regexp "bug" was just us forgetting that regexp is provided by user input, and should be validated. The bug as reported by Ramsay was here from the very beginning, i.e. commit 0e55991 (gitweb: Clearly distinguish regexp / exact match searches, 2008-02-26), which was present in v1.5.1 if I have checked correctly. The fix is about adding new code and should apply cleanly to 'maint' and even to older versions; the only trouble with older version might be whitespace issue related to refactoring code into subroutines.

Quoted 9 lines

The non-regexp project search bug was using $searchtext instead of $search_regexp as search regexp in gitweb. The bug was present from the very addition of project search, namely commit 0d1d154 (gitweb:
Support for simple project search form, 2008-10-03), which was present in v1.5.1 if I have checked correctly. Unfortunately the fix affects code that was changed recently in a1e1b2d (gitweb: improve usability of projects search form, 2012-01-31); I'll try to come up with equivalent patch to 'maint' soon (if the current one does not apply, and I guess it doesn't).

In other words: while "*foo" is invalid regular expression, it is perfectly valid fixed string search term (which translates to "\*foo" regexp).

Signature · 2 lines
Jakub Narebski
Poland
#14 lore raw

Re: [PATCH (BUGFIX)] gitweb: Fix fixed string (non-regexp) project search

In reply to Jakub Narebski
Quoted 4 lines · Jakub Narebski

.... The fix is about adding new code and should
apply cleanly to 'maint' and even to older versions; the only trouble with older version might be whitespace issue related to refactoring code into subroutines.

OK, so the global $searchtext is what came from form submit from the end user, while the global $search_regexp is what the code should be using for matching throughout the program, prepared by eval-and-validate-params.

Here is a hand-ported version of your patch that should apply to 1.7.6.6; does it look sane?

 gitweb/gitweb.perl |   12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
gitweb/gitweb.perl +6 -6
index 50a835a..d1698b7 100755
@@ -2905,10 +2905,10 @@ sub filter_forks_from_projects_list {
 sub search_projects_list {
 	my ($projlist, %opts) = @_;
 	my $tagfilter  = $opts{'tagfilter'};
-	my $searchtext = $opts{'searchtext'};
+	my $search_re = $opts{'search_regexp'};
 
 	return @$projlist
-		unless ($tagfilter || $searchtext);
+		unless ($tagfilter || $search_re);
 
 	my @projects;
  PROJECT:
@@ -2920,10 +2920,10 @@ sub search_projects_list {
 				grep { lc($_) eq lc($tagfilter) } keys %{$pr->{'ctags'}};
 		}
 
-		if ($searchtext) {
+		if ($search_re) {
 			next unless
-				$pr->{'path'} =~ /$searchtext/ ||
-				$pr->{'descr_long'} =~ /$searchtext/;
+				$pr->{'path'} =~ /$search_re/ ||
+				$pr->{'descr_long'} =~ /$search_re/;
 		}
 
 		push @projects, $pr;
@@ -5097,7 +5097,7 @@ sub git_project_list_body {
 	@projects = fill_project_list_info(\@projects);
 	# searching projects require filling to be run before it
 	@projects = search_projects_list(\@projects,
-	                                 'searchtext' => $searchtext,
+	                                 'search_regexp' => $search_regexp,
 	                                 'tagfilter'  => $tagfilter)
 		if ($tagfilter || $searchtext);
 
#15 lore raw

Re: [PATCH (BUGFIX)] gitweb: Fix fixed string (non-regexp) project search

Quoted 49 lines · Junio C Hamano
Quoted 4 lines · Jakub Narebski

.... The fix is about adding new code and should
apply cleanly to 'maint' and even to older versions; the only trouble with older version might be whitespace issue related to refactoring code into subroutines.

OK, so the global $searchtext is what came from form submit from the end user, while the global $search_regexp is what the code should be using for matching throughout the program, prepared by eval-and-validate-params.

Here is a hand-ported version of your patch that should apply to 1.7.6.6; does it look sane?

 gitweb/gitweb.perl |   12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
gitweb/gitweb.perl +5 -5
index 50a835a..d1698b7 100755
@@ -2905,10 +2905,10 @@ sub filter_forks_from_projects_list {
 sub search_projects_list {
 	my ($projlist, %opts) = @_;
 	my $tagfilter  = $opts{'tagfilter'};
-	my $searchtext = $opts{'searchtext'};
+	my $search_re = $opts{'search_regexp'};
 
 	return @$projlist
-		unless ($tagfilter || $searchtext);
+		unless ($tagfilter || $search_re);
 
 	my @projects;
  PROJECT:
@@ -2920,10 +2920,10 @@ sub search_projects_list {
 				grep { lc($_) eq lc($tagfilter) } keys %{$pr->{'ctags'}};
 		}
 
-		if ($searchtext) {
+		if ($search_re) {
 			next unless
-				$pr->{'path'} =~ /$searchtext/ ||
-				$pr->{'descr_long'} =~ /$searchtext/;
+				$pr->{'path'} =~ /$search_re/ ||
+				$pr->{'descr_long'} =~ /$search_re/;
 		}
 
 		push @projects, $pr;

gitweb/gitweb.perl sub git_project_list_body { · line 5103

Quoted 8 lines
gitweb/gitweb.perl +1 -1
@@ -5097,7 +5097,7 @@ sub git_project_list_body {
 	@projects = fill_project_list_info(\@projects);
 	# searching projects require filling to be run before it
 	@projects = search_projects_list(\@projects,
-	                                 'searchtext' => $searchtext,
+	                                 'search_regexp' => $search_regexp,
 	                                 'tagfilter'  => $tagfilter)
 		if ($tagfilter || $searchtext);
 

It looks sane, though

@projects = search_projects_list(\@projects,
- 'searchtext' => $searchtext,
+ 'search_regexp' => $search_regexp,
'tagfilter' => $tagfilter)
if ($tagfilter || $searchtext);

should be better written as

@projects = search_projects_list(\@projects,
- 'searchtext' => $searchtext,
+ 'search_regexp' => $search_regexp,
'tagfilter' => $tagfilter)

 - 		if ($tagfilter || $searchtext);
 + 		if ($tagfilter || $search_regexp);

It is functionally the same, because $search_regexp is derived from $searchtext, but IMHO it is more clear.

Signature · 2 lines
Jakub Narebski
Poland
#16 lore raw

Re: [PATCH (BUGFIX)] gitweb: Fix fixed string (non-regexp) project search

In reply to Jakub Narebski
Quoted 9 lines · Jakub Narebski
Quoted 6 lines

This patch solves the problem for me when using a regex search (re checkbox checked), but *not* for a non-regex search.

If you have a leading '*' or '+', in the non-regex case, then you still get the above complaint (and xml error page etc.), although the line number has changed slightly from that given above.

Ramsay, please provide those line number in the future, together with line and if possible some context.

Yeah, sorry about that; when I wrote that I didn't have the information readily available (I would have had to shutdown Windows, boot Linux, ...) and I was about to go out. So, the choice was to wait about 24hrs to report with full info, or provide the feedback earlier; I chose the latter. ;-)

Quoted 2 lines
 gitweb/gitweb.perl |   22 +++++++++++-----------
 1 files changed, 11 insertions(+), 11 deletions(-)

[patch snipped]

This patch works great for me. Thanks!

ATB,
Ramsay Jones

#17 lore raw

Re: [PATCH (BUGFIX)] gitweb: Fix fixed string (non-regexp) project search

Quoted 9 lines · Ramsay Jones
Quoted 7 lines · Jakub Narebski
Quoted 6 lines

This patch solves the problem for me when using a regex search (re checkbox checked), but *not* for a non-regex search.

If you have a leading '*' or '+', in the non-regex case, then you still get the above complaint (and xml error page etc.), although the line number has changed slightly from that given above.

Quoted 6 lines
Quoted 2 lines

Ramsay, please provide those line number in the future, together with line and if possible some context.

Yeah, sorry about that; when I wrote that I didn't have the information readily available (I would have had to shutdown Windows, boot Linux, ...) and I was about to go out.

You could have told us _that_...

Quoted 2 lines

So, the choice was to wait about 24hrs to report
with full info, or provide the feedback earlier; I chose the latter. ;-)

That's understandable.

Thanks again for reporting these issues.

Signature · 2 lines
Jakub Narebski
Poland