Commit a628b7c1 authored by Frédéric Buclin's avatar Frédéric Buclin

Bug 585028: Advanced Shortcut for Priority (P1-5 as search word) broken

r/a=mkanat
parent 62b0b5a0
...@@ -30,6 +30,9 @@ use Bugzilla::Status; ...@@ -30,6 +30,9 @@ use Bugzilla::Status;
use Bugzilla::Field; use Bugzilla::Field;
use Bugzilla::Util; use Bugzilla::Util;
use List::Util qw(min max);
use List::MoreUtils qw(firstidx);
use base qw(Exporter); use base qw(Exporter);
@Bugzilla::Search::Quicksearch::EXPORT = qw(quicksearch); @Bugzilla::Search::Quicksearch::EXPORT = qw(quicksearch);
...@@ -434,21 +437,33 @@ sub _special_field_syntax { ...@@ -434,21 +437,33 @@ sub _special_field_syntax {
# P1-5 Syntax # P1-5 Syntax
if ($word =~ m/^P(\d+)(?:-(\d+))?$/i) { if ($word =~ m/^P(\d+)(?:-(\d+))?$/i) {
my $start = $1 - 1; my ($p_start, $p_end) = ($1, $2);
$start = 0 if $start < 0;
my $end = $2 - 1;
my $legal_priorities = get_legal_field_values('priority'); 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]; 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]) $prios = join(',', @$legal_priorities[$start..$end])
} }
addChart('priority', 'anyexact', $prios, $negate); addChart('priority', 'anyexact', $prios, $negate);
return 1; return 1;
} }
return 0; return 0;
} }
...@@ -504,7 +519,12 @@ sub splitString { ...@@ -504,7 +519,12 @@ sub splitString {
@quoteparts = split(/"/, $string); @quoteparts = split(/"/, $string);
foreach my $part (@quoteparts) { foreach my $part (@quoteparts) {
# After every odd quote, quote special chars # 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 # Join again
$string = join('"', @quoteparts); $string = join('"', @quoteparts);
...@@ -517,9 +537,6 @@ sub splitString { ...@@ -517,9 +537,6 @@ sub splitString {
# as it has a special meaning. Strings which start with # as it has a special meaning. Strings which start with
# "+" must be quoted. # "+" must be quoted.
s/(?<!^)\+/%2B/g; s/(?<!^)\+/%2B/g;
# Also protect the minus sign from being considered
# as negation, in quotes.
s/(?<!^)\-/%2D/g;
# Remove quotes # Remove quotes
s/"//g; s/"//g;
} }
......
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