From: Dagfinn Ilmari Mannsåker Date: Sun, 8 Dec 2013 17:01:03 +0000 (+0000) Subject: Disallow { -in => undef } X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=90c87778411c072ba31879f7eb8991adc72ff6e4;p=dbsrgits%2FSQL-Abstract.git Disallow { -in => undef } It's ambiguous whether the user meant [ undef ] or [], or forgot to assign to a variable intended to hold an arrayref. --- diff --git a/lib/SQL/Abstract/Converter.pm b/lib/SQL/Abstract/Converter.pm index 0d7e064..42a25d0 100644 --- a/lib/SQL/Abstract/Converter.pm +++ b/lib/SQL/Abstract/Converter.pm @@ -483,6 +483,7 @@ sub _where_hashpair_to_dq { } }; if ($op eq 'BETWEEN' or $op eq 'IN' or $op eq 'NOT IN' or $op eq 'NOT BETWEEN') { + die "Can't use undef argument for operator $op" unless defined $rhs; $rhs = [$rhs] unless ref $rhs; if (ref($rhs) ne 'ARRAY') { if ($op =~ /IN$/) { diff --git a/t/01generate.t b/t/01generate.t index f876e60..57608c6 100644 --- a/t/01generate.t +++ b/t/01generate.t @@ -594,6 +594,11 @@ my @tests = ( stmt_q => 'SELECT * FROM `test` WHERE ( `a` IS NOT NULL AND `b` IS NOT NULL )', bind => [], }, + { + func => 'select', + args => ['test', '*', { a => { -in => undef } }], + exception_like => qr/Can't use undef argument for operator IN/, + }, ); for my $t (@tests) {