Commit 28055c61 authored by jocuri%softhome.net's avatar jocuri%softhome.net

Patch for bug 275788: Provide a line of code that defines legal query formats…

Patch for bug 275788: Provide a line of code that defines legal query formats for other scripts to use; patch by Colin S. Ogilvie <colin.ogilvie@gmail.com>, r=vladd, a=justdave.
parent 7f51d138
...@@ -32,6 +32,8 @@ use strict; ...@@ -32,6 +32,8 @@ use strict;
use vars qw($userid); use vars qw($userid);
package Bugzilla::Search; package Bugzilla::Search;
use base qw(Exporter);
@Bugzilla::Search::EXPORT = qw(IsValidQueryType);
use Bugzilla::Config; use Bugzilla::Config;
use Bugzilla::Error; use Bugzilla::Error;
...@@ -1436,4 +1438,13 @@ sub ValidateGroupName { ...@@ -1436,4 +1438,13 @@ sub ValidateGroupName {
return $ret; return $ret;
} }
# Validate that the query type is one we can deal with
sub IsValidQueryType
{
my ($queryType) = @_;
if (grep { $_ eq $queryType } qw(specific advanced)) {
return 1;
}
return 0;
}
1; 1;
...@@ -30,6 +30,7 @@ use lib "."; ...@@ -30,6 +30,7 @@ use lib ".";
require "CGI.pl"; require "CGI.pl";
use Bugzilla::Constants; use Bugzilla::Constants;
use Bugzilla::Search;
use vars qw( use vars qw(
@CheckOptionValues @CheckOptionValues
...@@ -439,7 +440,7 @@ if (!($cgi->param('query_format') || $cgi->param('format'))) { ...@@ -439,7 +440,7 @@ if (!($cgi->param('query_format') || $cgi->param('format'))) {
# Set cookie to current format as default, but only if the format # Set cookie to current format as default, but only if the format
# one that we should remember. # one that we should remember.
if (grep { $_ eq $vars->{'format'} } qw(specific advanced)) { if (IsValidQueryType($vars->{'format'})) {
$cgi->send_cookie(-name => 'DEFAULTFORMAT', $cgi->send_cookie(-name => 'DEFAULTFORMAT',
-value => $vars->{'format'}, -value => $vars->{'format'},
-expires => "Fri, 01-Jan-2038 00:00:00 GMT"); -expires => "Fri, 01-Jan-2038 00:00:00 GMT");
......
...@@ -27,6 +27,7 @@ use lib qw(.); ...@@ -27,6 +27,7 @@ use lib qw(.);
use Bugzilla; use Bugzilla;
use Bugzilla::Constants; use Bugzilla::Constants;
use Bugzilla::Search;
require "CGI.pl"; require "CGI.pl";
...@@ -304,13 +305,18 @@ sub DoSavedSearches() { ...@@ -304,13 +305,18 @@ sub DoSavedSearches() {
my @queries = @{Bugzilla->user->queries}; my @queries = @{Bugzilla->user->queries};
my @newqueries; my @newqueries;
foreach my $q (@queries) { foreach my $q (@queries) {
if ($q->{'query'} !~ /query_format=(advanced|specific)/) { if ($q->{'query'} =~ /query_format=([^&]*)/) {
if ($q->{'query'} =~ /query_format=&/) { my $format = $1;
$q->{'query'} =~ s/query_format=&/query_format=advanced&/; if (!IsValidQueryType($format)) {
} if ($format eq "") {
else { $q->{'query'} =~ s/query_format=/query_format=advanced/;
$q->{'query'} .= '&query_format=advanced'; }
else {
$q->{'query'} .= '&query_format=advanced';
}
} }
} else {
$q->{'query'} .= '&query_format=advanced';
} }
push @newqueries, $q; push @newqueries, $q;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment