From: Don Armstrong <don@donarmstrong.com>
Date: Sat, 21 Feb 2015 08:05:01 +0000 (-0800)
Subject: add test for get_bug_order_index; fix faulty regex in while()
X-Git-Tag: release/2.6.0~234
X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=ff74063bdaf0d398417c71e1fe8f58c916f0fb00;p=debbugs.git

add test for get_bug_order_index; fix faulty regex in while()
---

diff --git a/Debbugs/CGI/Pkgreport.pm b/Debbugs/CGI/Pkgreport.pm
index da937e55..77b55165 100644
--- a/Debbugs/CGI/Pkgreport.pm
+++ b/Debbugs/CGI/Pkgreport.pm
@@ -469,21 +469,15 @@ sub get_bug_order_index {
 
      for my $el (@${order}) {
 	  $pos++;
-	  my $match = 0;
+	  my $match = 1;
           my $first_field = 1; # true if no previous fields have been
                                # checked
-          while ($el =~ /(?<joiner>^|\+|,)(?<field>[^=]+)=(?<value>[^=,\+])/g) {
+          while ($el =~ /(?<joiner>^|\+|,)(?<field>[^=]+)=(?<value>[^=,\+]+)/g) {
               my ($j,$f,$v) = @+{qw(joiner field value)};
-              if (not defined $j) {
-                  $j = '+';
-              }
-              if ($j eq '+' and $first_field) {
-                  $match = 1;
-              }
               my $isokay = 0;
               $isokay = 1 if (defined $status->{$f} and $v eq $status->{$f});
               $isokay = 1 if ($f eq "tag" && defined $tags{$v});
-              if ($j eq ',') {
+              if (defined $j and $j eq ',') {
                   $match ||= $isokay;
               } else {
                   $match &&= $isokay;
@@ -493,8 +487,8 @@ sub get_bug_order_index {
           # if there is a match, or if there were no fields to check,
           # this usertag matched.
 	  if ($match || $first_field) {
-	       return $pos;
-	       last;
+              return $pos;
+              last;
 	  }
      }
      return $pos + 1;
diff --git a/t/16_usertags.t b/t/16_usertags.t
new file mode 100644
index 00000000..26a1e3d9
--- /dev/null
+++ b/t/16_usertags.t
@@ -0,0 +1,39 @@
+# -*- mode: cperl;-*-
+
+use Test::More;
+
+use warnings;
+use strict;
+
+plan tests => 4;
+
+use_ok('Debbugs::CGI::Pkgreport');
+
+my @usertags = ('severity=serious,severity=grave,severity=critical',
+                'tag=second',
+                'tag=third',
+                '',
+               );
+
+my @bugs =
+    ({severity => 'normal',
+      tag => 'wrongtag',
+      order => 3,
+     },
+    {severity => 'critical',
+     tag => 'second',
+     order => 0,
+    },
+    {severity => 'normal',
+     tag => 'third',
+     order => 2,
+    },
+    );
+
+for my $bug (@bugs) {
+    ok(Debbugs::CGI::Pkgreport::get_bug_order_index(\@usertags,$bug) == $bug->{order},
+       "order is actually $bug->{order}",
+      );
+}
+
+