[Rt-commit] rt branch, 4.4/columns-as-values-in-ticket-search, updated. rt-4.4.4-21-g771ee67205

? sunnavy sunnavy at bestpractical.com
Wed Nov 20 17:14:30 EST 2019


The branch, 4.4/columns-as-values-in-ticket-search has been updated
       via  771ee67205471a8d68717684e5e87a16913271c8 (commit)
       via  75d348fa6b4fe9eb0545334acdaebc079dfa71a6 (commit)
      from  e21fdf5346e44547c8100262846a81f0bbaa2608 (commit)

Summary of changes:
 lib/RT/SQL.pm     | 15 +++++++++++++--
 lib/RT/Tickets.pm | 15 ++++++++-------
 t/api/tickets.t   |  8 ++++++++
 3 files changed, 29 insertions(+), 9 deletions(-)

- Log -----------------------------------------------------------------
commit 75d348fa6b4fe9eb0545334acdaebc079dfa71a6
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Nov 21 04:31:26 2019 +0800

    Set QUOTEVALUE only if necessary to use default behavior as much as possible
    
    Previously QUOTEVALUE was set to 1/0 totally depending on if the value
    is quoted or not in ticket SQL. This is incorrect and could cause SQL
    generated by queries like "CF.foo LIKE 3" not been quoted correctly:
    
        ObjectCustomFieldValues_1.Content LIKE %3%
    
    This issue was introduced when we supported columns as values. To fix
    this issue, besides actually quoted values where QUOTEVALUE should be 1,
    we only need to specifically set QUOTEVALUE to 0 when values are columns
    and let the default behavior handle other cases.

diff --git a/lib/RT/SQL.pm b/lib/RT/SQL.pm
index e6545e32ad..3d81047dc9 100644
--- a/lib/RT/SQL.pm
+++ b/lib/RT/SQL.pm
@@ -177,8 +177,19 @@ sub Parse {
                 s!\\(.)!$1!g;
             }
 
-            my $value_is_quoted = $match =~ $re_delim ? 1 : 0;
-            $cb->{'Condition'}->( $key, $op, $value, $value_is_quoted );
+            my $quote_value;
+            if ( $match =~ /$re_delim/o ) {
+                $quote_value = 1;
+            }
+            elsif ( $match =~ /^[a-z]/i ) {
+                # Value is a column
+                $quote_value = 0;
+            }
+            else {
+                # Not setting value here to fallback to default behavior
+            }
+
+            $cb->{'Condition'}->( $key, $op, $value, $quote_value );
 
             ($key,$op,$value) = ("","","");
             $want = AGGREG;
diff --git a/lib/RT/Tickets.pm b/lib/RT/Tickets.pm
index cd9fbbb419..4532c02b58 100644
--- a/lib/RT/Tickets.pm
+++ b/lib/RT/Tickets.pm
@@ -3191,7 +3191,7 @@ sub _parser {
             my $sub = $dispatch{ $class }
                 or die "No dispatch method for class '$class'";
 
-            if ( !$quote_value && $value !~ /^(?:[+-]?[0-9]+|NULL)$/i ) {
+            if ( defined $quote_value && !$quote_value && $value !~ /^(?:[+-]?[0-9]+|NULL)$/i ) {
                 my ( $class, $field );
 
                 # e.g. CF.Foo or CF.{Beta Date}
@@ -3266,12 +3266,13 @@ sub _parser {
 
             # A reference to @res may be pushed onto $sub_tree{$key} from
             # above, and we fill it here.
-            $sub->( $self, $key, $op, $value,
-                    ENTRYAGGREGATOR => $ea,
-                    SUBKEY          => $subkey,
-                    BUNDLE          => $bundle,
-                    QUOTEVALUE      => $quote_value,
-                  );
+            $sub->(
+                $self, $key, $op, $value,
+                ENTRYAGGREGATOR => $ea,
+                SUBKEY          => $subkey,
+                BUNDLE          => $bundle,
+                defined $quote_value ? ( QUOTEVALUE => $quote_value ) : (),
+            );
         },
         sub {
             my $node = shift;

commit 771ee67205471a8d68717684e5e87a16913271c8
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Nov 21 05:41:09 2019 +0800

    Add regression tests for integers as CF values in search

diff --git a/t/api/tickets.t b/t/api/tickets.t
index 895aca1f19..2955bf2875 100644
--- a/t/api/tickets.t
+++ b/t/api/tickets.t
@@ -216,6 +216,14 @@ ok( $unlimittickets->Count > 0, "UnLimited tickets object should return tickets"
     $count = $tickets->Count();
     is( $count, 0, 'Found 0 tickets' );
 
+    ok( $ticket->AddCustomFieldValue( Field => $cf_foo, Value => '1900' ) );
+    for my $operator ( '=', 'LIKE' ) {
+        ( $ret, $msg ) = $tickets->FromSQL("CF.foo $operator 1900");
+        ok( $ret, "Ran query with CF.foo $operator 1900" );
+        $count = $tickets->Count();
+        is( $count, 1, 'Found 1 ticket' );
+    }
+
     ok( $ticket->AddCustomFieldValue( Field => $cf_beta, Value => $date->ISO( Timezone => 'user' ) ) );
     ( $ret, $msg ) = $tickets->FromSQL('Due = CF.{Beta Date}');
     ok( $ret, 'Ran query with Due = CF.{Beta Date}' );

-----------------------------------------------------------------------


More information about the rt-commit mailing list