]> git.donarmstrong.com Git - debbugs.git/blobdiff - Debbugs/CGI/Pkgreport.pm
Call encode_utf8 in generate_package_info
[debbugs.git] / Debbugs / CGI / Pkgreport.pm
index d047affb1d262827d204552b3fc4c52ece4e9b63..2d0de6f6c74803a704948c31e9fb7ba1961e34ce 100644 (file)
@@ -41,6 +41,7 @@ use Debbugs::Bugs qw(bug_filter);
 use Debbugs::Packages qw(:mapping);
 
 use Debbugs::Text qw(:templates);
+use Encode qw(encode_utf8);
 
 use POSIX qw(strftime);
 
@@ -107,7 +108,8 @@ sub generate_package_info{
      }
      else {
          print {$output} "<p>There is no maintainer for $showpkg. ".
-              "Please do not report new bugs against this package.</p>\n";
+              "This means that this package no longer exists (or never existed). ".
+                  "Please do not report new bugs against this package. </p>\n";
      }
      my @pkgs = getsrcpkgs($srcforpkg);
      @pkgs = grep( !/^\Q$package\E$/, @pkgs );
@@ -130,9 +132,11 @@ sub generate_package_info{
               "list of other pseudo-packages</a>";
      }
      elsif (not defined $maint and not @{$param{bugs}}) {
-         print {$output} "<p>There is no record of the " . html_escape($package) .
-              ($param{binary} ? " package" : " source package") .
-                   ", and no bugs have been filed against it.</p>";
+       # don't bother printing out this information, because it's
+       # already present above.
+       #  print {$output} "<p>There is no record of the " . html_escape($package) .
+       #       ($param{binary} ? " package" : " source package") .
+       #           ", and no bugs have been filed against it.</p>";
      }
      else {
          if ($package and defined $config{package_pages} and length $config{package_pages}) {
@@ -164,7 +168,7 @@ sub generate_package_info{
          printf {$output} "<a href=\"%s\">report it</a>.</p>\n",
               html_escape("http://$config{web_domain}/Reporting$config{html_suffix}");
      }
-     return $output_scalar;
+     return encode_utf8($output_scalar);
 }
 
 
@@ -221,7 +225,7 @@ sub short_bug_status_html {
      if (@blockedby && $status{"pending"} ne 'fixed' && ! length($status{done})) {
          for my $b (@blockedby) {
               my %s = %{get_bug_status($b)};
-              next if $s{"pending"} eq 'fixed' || length $s{done};
+              next if (defined $s{pending} and $s{pending} eq 'fixed') or (defined $s{done} and length $s{done});
               push @{$status{blockedby_array}},{bug_num => $b, subject => $s{subject}, status => \%s};
          }
      }
@@ -455,35 +459,57 @@ sub pkg_htmlizebugs {
      return $result;
 }
 
+sub parse_order_statement_into_boolean {
+    my ($statement,$status,$tags) = @_;
+
+    if (not defined $tags) {
+        $tags = {map { $_, 1 } split / /, $status->{"tags"}
+                }
+            if defined $status->{"tags"};
+
+    }
+    # replace all + with &&
+    $statement =~ s/\+/&&/g;
+    # replace all , with ||
+    $statement =~ s/,/||/g;
+    $statement =~ s{([^\&\|\=]+) # field
+                    =
+                    ([^\&\|\=]+) # value
+              }{
+                  my $ok = 0;
+                  if ($1 eq 'tag') {
+                      $ok = 1 if defined $tags->{$2};
+                  } else {
+                      $ok = 1 if defined $status->{$1} and
+                          $status->{$1} eq $2;
+                  }
+                  $ok;
+              }exg;
+    # check that the parsed statement is just valid boolean statements
+    if ($statement =~ /^([01\(\)\&\|]+)$/) {
+        return eval "$1";
+    } else {
+        # this is an invalid boolean statement
+        return 0;
+    }
+}
+
 sub get_bug_order_index {
      my $order = shift;
      my $status = shift;
-     my $pos = -1;
-
-     my %tags = ();
-     %tags = map { $_, 1 } split / /, $status->{"tags"}
-         if defined $status->{"tags"};
-
+     my $pos = 0;
+     my $tags = {map { $_, 1 } split / /, $status->{"tags"}
+                }
+         if defined $status->{"tags"};
      for my $el (@${order}) {
-         $pos++;
-         my $match = 1;
-         for my $item (split /[+]/, $el) {
-              my ($f, $v) = split /=/, $item, 2;
-              next unless (defined $f and defined $v);
-              my $isokay = 0;
-              $isokay = 1 if (defined $status->{$f} and $v eq $status->{$f});
-              $isokay = 1 if ($f eq "tag" && defined $tags{$v});
-              unless ($isokay) {
-                   $match = 0;
-                   last;
-              }
-         }
-         if ($match) {
-              return $pos;
-              last;
-         }
+         if (not length $el or
+             parse_order_statement_into_boolean($el,$status,$tags)
+            ) {
+             return $pos;
+         }
+         $pos++;
      }
-     return $pos + 1;
+     return $pos;
 }
 
 # sets: my @names; my @prior; my @title; my @order;