diff --git a/src/backend/BSFileDB.pm b/src/backend/BSFileDB.pm index 5901a08231c..933493b3942 100644 --- a/src/backend/BSFileDB.pm +++ b/src/backend/BSFileDB.pm @@ -51,6 +51,12 @@ sub decode_line { return $r; } +sub encode_field { + my ($str) = @_; + $str =~ s/([\000-\037%|=\177-\237])/sprintf("%%%02X", ord($1))/ge; + return $str; +} + sub encode_line { my ($r, $lay) = @_; my @line; @@ -229,9 +235,15 @@ sub fdb_getall_reverse { @l = split("\n", $buf, -1); } for (reverse @l) { - my $r = decode_line($_, $lay); + my $r = $_; + $r = decode_line($_, $lay) if defined($lay); if ($filter) { - my $f = $filter->($r); + my $f; + if (defined($lay)) { + $f = $filter->($r); + } else { + $f = $filter->(split('\|', $r)); + } next unless $f; if ($f < 0) { push @res, $r if $f == -1; diff --git a/src/backend/bs_repserver b/src/backend/bs_repserver index b039d1c18c1..48fc44b59c2 100755 --- a/src/backend/bs_repserver +++ b/src/backend/bs_repserver @@ -3154,24 +3154,30 @@ sub getjobhistory { if ($cgi->{'code'} && @{$cgi->{'code'}} == 1 && $cgi->{'code'}->[0] eq 'lastfailures') { return getlastfailures($cgi, $projid, $repoid, $arch); } + my $idx = 0; + my %indices = map {$_ => $idx++} @$BSXML::jobhistlay; + my $packidx = $indices{'package'}; + my $codeidx = $indices{'code'}; + my $endtimeidx = $indices{'endtime'}; if ($cgi->{'package'} && $cgi->{'code'}) { - my %packid = map {$_ => 1} @{$cgi->{'package'}}; + my %packid = map {BSFileDB::encode_field($_) => 1} @{$cgi->{'package'}}; my %code = map {$_ => 1} @{$cgi->{'code'}}; - $filter = sub {$packid{$_[0]->{'package'}} && $code{$_[0]->{'code'}}}; + $filter = sub {$packid{$_[$packidx]} && $code{$_[$codeidx]}}; } elsif ($cgi->{'package'}) { - my %packid = map {$_ => 1} @{$cgi->{'package'}}; - $filter = sub {$packid{$_[0]->{'package'}}}; + my %packid = map {BSFileDB::encode_field($_) => 1} @{$cgi->{'package'}}; + $filter = sub {$packid{$_[$packidx]}}; } elsif ($cgi->{'code'}) { my %code = map {$_ => 1} @{$cgi->{'code'}}; - $filter = sub {$code{$_[0]->{'code'}}}; + $filter = sub {$code{$_[$codeidx]}}; } - if ($cgi->{'endtime_start'} || $cgi->{'endtime_end'} || 1) { + if ($cgi->{'endtime_start'} || $cgi->{'endtime_end'}) { my $filter2 = $filter; my $endtime_start = $cgi->{'endtime_start'} || 0; my $endtime_end = $cgi->{'endtime_end'}; - $filter = sub {$_[0]->{'endtime'} < $endtime_start ? -2 : defined($endtime_end) && $_[0]->{'endtime'} > $endtime_end ? 0 : $filter2 ? $filter2->($_[0]) : 1}; + $filter = sub { $_[$endtimeidx] < $endtime_start ? -2 : defined($endtime_end) && $_[$endtimeidx] > $endtime_end ? 0 : $filter2 ? $filter2->(@_) : 1 }; } - my @hist = BSFileDB::fdb_getall_reverse("$reporoot/$projid/$repoid/$arch/:jobhistory", $BSXML::jobhistlay, $cgi->{'limit'} || 100, $filter); + my @hist = BSFileDB::fdb_getall_reverse("$reporoot/$projid/$repoid/$arch/:jobhistory", undef, $cgi->{'limit'} || 100, $filter); + @hist = map {BSFileDB::decode_line($_, $BSXML::jobhistlay)} @hist; @hist = reverse @hist; my $ret = {jobhist => \@hist}; return ($ret, $BSXML::jobhistlist);