From: Peter Rabbitson Date: Fri, 7 Jan 2011 09:18:32 +0000 (+0100) Subject: Fix incorrect comparison of malformed lists X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7cc4731935b0b0e60c7d4ebe44512de74de5dc3c;p=scpubgit%2FQ-Branch.git Fix incorrect comparison of malformed lists AND OR and , must have both a lhs and a rhs, if neither is present add a [], which will properly trip the comparison later on. --- diff --git a/Changes b/Changes index 13b7b1b..890c648 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,7 @@ Revision history for SQL::Abstract - Fix parsing of NOT EXISTS - Fix deep recursion warnings while parsing obnoxiously long sql statements + - Fix incorrect comparison of malformed lists revision 1.72 2010-12-21 ---------------------------- diff --git a/lib/SQL/Abstract/Tree.pm b/lib/SQL/Abstract/Tree.pm index 8d7a36a..1da83de 100644 --- a/lib/SQL/Abstract/Tree.pm +++ b/lib/SQL/Abstract/Tree.pm @@ -348,14 +348,14 @@ sub _recurse_parse { elsif ($token =~ /^ (?: OR | AND | \, ) $/xi ) { my $op = ($token eq ',') ? 'LIST' : uc $token; - my $right = $self->_recurse_parse($tokens, PARSE_IN_EXPR); + my $right = $self->_recurse_parse($tokens, PARSE_IN_EXPR) || []; # Merge chunks if logic matches - if (ref $right and $op eq $right->[0]) { - $left = [ (shift @$right ), [$left||(), map { @$_ } @$right] ]; + if (ref $right and @$right and $op eq $right->[0]) { + $left = [ (shift @$right ), [$left||[], map { @$_ } @$right] ]; } else { - $left = [$op => [ $left||(), $right||() ]]; + $left = [$op => [ $left||[], $right ]]; } } # binary operator keywords diff --git a/t/10test.t b/t/10test.t index 4d14014..b5d4829 100644 --- a/t/10test.t +++ b/t/10test.t @@ -615,6 +615,20 @@ my @sql_tests = ( 'SELECT * FROM foo WHERE a IN (3,2,1)', ] }, + + # list consistency + { + equal => 0, + statements => [ + 'SELECT a,b FROM foo', + 'SELECT a,,b FROM foo', + 'SELECT a,b, FROM foo', + 'SELECT ,a,b, FROM foo', + 'SELECT ,a,,b, FROM foo', + ], + }, + + # misc func { equal => 0, statements => [ @@ -625,7 +639,6 @@ my @sql_tests = ( 'SELECT count(1) FROM foo', ] }, - # misc func { equal => 1, statements => [