summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Search
diff options
context:
space:
mode:
authorFrédéric Buclin <LpSolit@gmail.com>2010-09-21 18:25:40 +0200
committerFrédéric Buclin <LpSolit@gmail.com>2010-09-21 18:25:40 +0200
commita628b7c148ae563396b02500442077a3a2979432 (patch)
treed5fe6b8d763c30d45bd600558b70a64946f624a3 /Bugzilla/Search
parent62b0b5a07fddab7f308dc6ebbf2cf0a784c476ca (diff)
downloadbugzilla-a628b7c148ae563396b02500442077a3a2979432.tar.gz
bugzilla-a628b7c148ae563396b02500442077a3a2979432.tar.xz
Bug 585028: Advanced Shortcut for Priority (P1-5 as search word) broken
r/a=mkanat
Diffstat (limited to 'Bugzilla/Search')
-rw-r--r--Bugzilla/Search/Quicksearch.pm41
1 files changed, 29 insertions, 12 deletions
diff --git a/Bugzilla/Search/Quicksearch.pm b/Bugzilla/Search/Quicksearch.pm
index 602b78af0..f98bd54d2 100644
--- a/Bugzilla/Search/Quicksearch.pm
+++ b/Bugzilla/Search/Quicksearch.pm
@@ -30,6 +30,9 @@ use Bugzilla::Status;
use Bugzilla::Field;
use Bugzilla::Util;
+use List::Util qw(min max);
+use List::MoreUtils qw(firstidx);
+
use base qw(Exporter);
@Bugzilla::Search::Quicksearch::EXPORT = qw(quicksearch);
@@ -434,21 +437,33 @@ sub _special_field_syntax {
# P1-5 Syntax
if ($word =~ m/^P(\d+)(?:-(\d+))?$/i) {
- my $start = $1 - 1;
- $start = 0 if $start < 0;
- my $end = $2 - 1;
-
+ my ($p_start, $p_end) = ($1, $2);
my $legal_priorities = get_legal_field_values('priority');
- $end = scalar(@$legal_priorities) - 1
- if $end > (scalar @$legal_priorities - 1);
+
+ # If Pn exists explicitly, use it.
+ my $start = firstidx { $_ eq "P$p_start" } @$legal_priorities;
+ my $end;
+ $end = firstidx { $_ eq "P$p_end" } @$legal_priorities if defined $p_end;
+
+ # If Pn doesn't exist explicitly, then we mean the nth priority.
+ if ($start == -1) {
+ $start = max(0, $p_start - 1);
+ }
my $prios = $legal_priorities->[$start];
- if ($end) {
+
+ if (defined $end) {
+ # If Pn doesn't exist explicitly, then we mean the nth priority.
+ if ($end == -1) {
+ $end = min(scalar(@$legal_priorities), $p_end) - 1;
+ $end = max(0, $end); # Just in case the user typed P0.
+ }
+ ($start, $end) = ($end, $start) if $end < $start;
$prios = join(',', @$legal_priorities[$start..$end])
}
+
addChart('priority', 'anyexact', $prios, $negate);
return 1;
}
-
return 0;
}
@@ -504,7 +519,12 @@ sub splitString {
@quoteparts = split(/"/, $string);
foreach my $part (@quoteparts) {
# After every odd quote, quote special chars
- $part = url_quote($part) if $i++ % 2;
+ if ($i++ %2) {
+ $part = url_quote($part);
+ # Protect the minus sign from being considered
+ # as negation, in quotes.
+ $part =~ s/(?<=^)\-/%2D/;
+ }
}
# Join again
$string = join('"', @quoteparts);
@@ -517,9 +537,6 @@ sub splitString {
# as it has a special meaning. Strings which start with
# "+" must be quoted.
s/(?<!^)\+/%2B/g;
- # Also protect the minus sign from being considered
- # as negation, in quotes.
- s/(?<!^)\-/%2D/g;
# Remove quotes
s/"//g;
}