[Rt-commit] rt branch, 4.4/query-builder-operator-for-null, created. rt-4.4.2-78-g61f1199c8

? sunnavy sunnavy at bestpractical.com
Thu Feb 22 17:10:16 EST 2018


The branch, 4.4/query-builder-operator-for-null has been created
        at  61f1199c8eb92ad5803804318954b1866639174f (commit)

- Log -----------------------------------------------------------------
commit 4e8b7a473d9df25078d21efd7a00ac78ed60ab31
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Feb 23 04:19:45 2018 +0800

    set operator to "IS" or "IS NOT" for NULL values
    
    This is actually the old behavior of RT prior to 4.4. In b68c84f0
    (Switch to parsing into a parse tree as an IR), related code was deleted
    from old place but wasn't re-implemented in the new place.

diff --git a/lib/RT/Interface/Web/QueryBuilder/Tree.pm b/lib/RT/Interface/Web/QueryBuilder/Tree.pm
index d63a16d4b..fe0bee633 100644
--- a/lib/RT/Interface/Web/QueryBuilder/Tree.pm
+++ b/lib/RT/Interface/Web/QueryBuilder/Tree.pm
@@ -213,14 +213,19 @@ sub __LinearizeTree {
                 $key = "'$key'";
             }
             my $value = $clause->{Value};
-            if ( $clause->{Op} =~ /^IS( NOT)?$/i ) {
+            my $op = $clause->{Op};
+            if ( $value =~ /^NULL$/i && $op =~ /^(!?)=$/  ) {
+                $op = $1 ? 'IS NOT' : 'IS';
+            }
+
+            if ( $op =~ /^IS( NOT)?$/i ) {
                 $value = 'NULL';
             } elsif ( $value !~ /^[+-]?[0-9]+$/ ) {
                 $value =~ s/(['\\])/\\$1/g;
                 $value = "'$value'";
             }
 
-            $str .= $key ." ". $clause->{Op} . " " . $value;
+            $str .= $key ." ". $op . " " . $value;
         }
         $str =~ s/^\s+|\s+$//;
 

commit 61f1199c8eb92ad5803804318954b1866639174f
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Feb 23 05:44:10 2018 +0800

    test null values in query builder

diff --git a/t/web/query_builder_null_values.t b/t/web/query_builder_null_values.t
new file mode 100644
index 000000000..4539b6699
--- /dev/null
+++ b/t/web/query_builder_null_values.t
@@ -0,0 +1,49 @@
+use strict;
+use warnings;
+
+use RT::Test tests => undef;
+
+my $cf = RT::Test->load_or_create_custom_field(
+    Name  => 'foo',
+    Type  => 'FreeformSingle',
+    Queue => 0,
+);
+
+RT::Test->create_tickets(
+    { Queue   => 'General' },
+    { Subject => 'ticket bar', 'CustomField-' . $cf->id => 'bar' },
+    { Subject => 'ticket baz', 'CustomField-' . $cf->id => 'baz' },
+    { Subject => 'ticket null' },
+);
+
+my ( $baseurl, $m ) = RT::Test->started_ok;
+ok( $m->login, 'logged in' );
+
+$m->get_ok( '/Search/Build.html' );
+$m->submit_form(
+    form_name => 'BuildQuery',
+    fields    => { 'CF.{foo}Op' => '=', 'ValueOfCF.{foo}' => 'NULL', },
+    button    => 'DoSearch',
+);
+
+$m->title_is( 'Found 1 ticket', 'found 1 ticket with CF.{foo} IS NULL' );
+$m->content_contains( 'ticket null', 'has ticket null' );
+$m->follow_link_ok( { text => 'Advanced' } );
+$m->text_lacks( q[CF.{foo} = 'NULL'] );
+$m->text_contains( 'CF.{foo} IS NULL', q["= 'NULL'" is converted to "IS NULL"] );
+
+$m->get_ok( '/Search/Build.html?NewQuery=1' );
+$m->submit_form(
+    form_name => 'BuildQuery',
+    fields    => { 'CF.{foo}Op' => '!=', 'ValueOfCF.{foo}' => 'NULL', },
+    button    => 'DoSearch',
+);
+
+$m->title_is( 'Found 2 tickets', 'found 2 ticket with CF.{foo} IS NOT NULL' );
+$m->content_contains( 'ticket bar', 'has ticket bar' );
+$m->content_contains( 'ticket baz', 'has ticket baz' );
+$m->follow_link_ok( { text => 'Advanced' } );
+$m->text_lacks( q[CF.{foo} != 'NULL'] );
+$m->text_contains( 'CF.{foo} IS NOT NULL', q["!= 'NULL'" is converted to "IS NOT NULL"] );
+
+done_testing;

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


More information about the rt-commit mailing list