From: Matt S Trout <mst@shadowcat.co.uk>
Date: Sat, 21 Sep 2019 20:15:00 +0000 (+0000)
Subject: detect disabled ops earlier and fail
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=296a423dc322ecc38cd0400051c26d447a69bc22;p=scpubgit%2FQ-Branch.git

detect disabled ops earlier and fail
---

diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm
index 79c6300..4b4c08f 100644
--- a/lib/SQL/Abstract.pm
+++ b/lib/SQL/Abstract.pm
@@ -686,19 +686,6 @@ sub _expand_hashpair_op {
 
   my $op = $self->_normalize_op($k);
 
-  if (my $exp = $self->{expand}{$op}) {
-    return $self->$exp($op, $v);
-  }
-
-  # Ops prefixed with -not_ get converted
-
-  if (my ($rest) = $op =~/^not_(.*)$/) {
-    return +{ -op => [
-      'not',
-      $self->_expand_expr({ "-${rest}", $v })
-    ] };
-  }
-
   { # Old SQLA compat
 
     my $op = join(' ', split '_', $op);
@@ -717,9 +704,27 @@ sub _expand_hashpair_op {
     ) {
       puke "Illegal use of top-level '-$op'"
     }
+  }
+
+  if (my $exp = $self->{expand}{$op}) {
+    return $self->$exp($op, $v);
+  }
+
+  # Ops prefixed with -not_ get converted
+
+  if (my ($rest) = $op =~/^not_(.*)$/) {
+    return +{ -op => [
+      'not',
+      $self->_expand_expr({ "-${rest}", $v })
+    ] };
+  }
+
+  { # Old SQLA compat
 
     # the old unary op system means we should touch nothing and let it work
 
+    my $op = join(' ', split '_', $op);
+
     if (my $us = List::Util::first { $op =~ $_->{regex} } @{$self->{unary_ops}}) {
       return { -op => [ $op, $v ] };
     }
diff --git a/t/21op_ident.t b/t/21op_ident.t
index 7fe09d3..d73b11c 100644
--- a/t/21op_ident.t
+++ b/t/21op_ident.t
@@ -17,6 +17,16 @@ for my $q ('', '"') {
     $sql_maker->where({ foo => { -ident => undef } })
   } qr/-ident requires a single plain scalar argument/;
 
+  throws_ok {
+    local $sql_maker->{disable_old_special_ops} = 1;
+    $sql_maker->where({'-or' => [{'-ident' => 'foo'},'foo']})
+  } qr/Illegal.*top-level/;
+
+  throws_ok {
+    local $sql_maker->{disable_old_special_ops} = 1;
+    $sql_maker->where({'-or' => [{'-ident' => 'foo'},{'=' => \'bozz'}]})
+  } qr/Illegal.*top-level/;
+
   my ($sql, @bind) = $sql_maker->select('artist', '*', { 'artist.name' => { -ident => 'artist.pseudonym' } } );
   is_same_sql_bind (
     $sql,