Fix and try to avoid "list Package->.." bug

hinted-selects
Vitaliy Filippov 2014-10-17 16:12:54 +04:00
parent 04caa11915
commit 696a70c226
5 changed files with 11 additions and 5 deletions

View File

@ -83,7 +83,6 @@ sub _die_error
{
if ($msg =~ /lock wait|deadlock found/i)
{
use Data::Dumper;
# Log active InnoDB locks
my $locks = Bugzilla->dbh->selectall_arrayref('SELECT * FROM information_schema.innodb_locks', {Slice=>{}});
$msg = "InnoDB locks:\n".Dumper($locks)."\n".$msg;

View File

@ -173,7 +173,7 @@ sub new_from_list
foreach my $id (@$id_list)
{
detaint_natural($id) || ThrowCodeError('param_must_be_numeric', {function => $class . '::new_from_list'});
# Too large integers make PostgreSQL crash.
# Too large integers make PostgreSQL crash (FIXME: That's very STRANGE?!!)
next if $id > MAX_INT_32;
push(@detainted_ids, $id);
}

View File

@ -949,8 +949,15 @@ sub bz_encode_json
return $var;
}
# Return empty list for undef or expand an arrayref
sub list($)
{
# If you write "list Package->method->{something}", for example "list Bugzilla->input_params->{arg}",
# Perl parses it as "(list Package)->method->{something}". But most Bugzilla modules use Bugzilla::Util
# and thus have list() imported in their namespace, so (list Package) gets happily executed and you
# just get "Package->method->{something}" without list().
# Trry to fight it by checking if the calling context wants a list.
wantarray or die "Possible bug: Bugzilla::Util::list() called without wantarray. Do not write 'list Package->method->...'";
my ($array) = @_;
return () unless defined $array;
return ($array) if ref $array ne 'ARRAY';

View File

@ -269,7 +269,7 @@ exit;
# Find any selected series and return either the first or all of them.
sub getAndValidateSeriesIDs
{
my @series_ids = grep /^\d+$/, list Bugzilla->input_params->{name};
my @series_ids = grep /^\d+$/, list(Bugzilla->input_params->{name});
return wantarray ? @series_ids : $series_ids[0];
}

View File

@ -429,7 +429,7 @@ sub _do_add
$current = $group->grant_direct($type);
}
my $add_items = Bugzilla::Group->new_from_list([ list Bugzilla->input_params->{$field} ]);
my $add_items = Bugzilla::Group->new_from_list([ list(Bugzilla->input_params->{$field}) ]);
foreach my $add (@$add_items)
{
@ -450,7 +450,7 @@ sub _do_add
sub _do_remove
{
my ($group, $changes, $sth_delete, $field, $type, $reverse) = @_;
my $remove_items = Bugzilla::Group->new_from_list([ list Bugzilla->input_params->{$field} ]);
my $remove_items = Bugzilla::Group->new_from_list([ list(Bugzilla->input_params->{$field}) ]);
foreach my $remove (@$remove_items)
{