[Rt-commit] rt branch, 4.2/spurious-zero-cf, created. rt-4.2.13-67-g8810f2c

Shawn Moore shawn at bestpractical.com
Wed Nov 16 15:33:01 EST 2016


The branch, 4.2/spurious-zero-cf has been created
        at  8810f2c4bab60fb9c76ab85144160c5bfc820bab (commit)

- Log -----------------------------------------------------------------
commit 535efc7c13bb3b4522c9d70445eb3c3d80123110
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Wed Nov 16 20:20:00 2016 +0000

    Add failing tests for "CF changed from 0 to 0"
    
    for I#32440

diff --git a/t/web/cf_textarea.t b/t/web/cf_textarea.t
index d11bda4..444020e 100644
--- a/t/web/cf_textarea.t
+++ b/t/web/cf_textarea.t
@@ -27,6 +27,10 @@ my $cfs = {
         type => 'FreeformSingle',
         name => 'TheControlField',
     },
+    zero => {
+        type => 'FreeformSingle',
+        name => 'Zero',
+    },
 };
 
 while ( my( $label, $data ) = each %$cfs ) {
@@ -55,10 +59,13 @@ $m->submit_form_ok({
         $cfs->{area}{input} . '-Magic' => "1",
         $cfs->{text}{input}            => 'value a',
         $cfs->{text}{input} . '-Magic' => "1",
+        $cfs->{zero}{input}            => '0',
+        $cfs->{zero}{input} . '-Magic' => "1",
     },
 }, 'submitted form to initially set CFs');
 $m->content_contains('<li>TheControlField value a added</li>');
 $m->content_contains("<li>TheTextarea $content added</li>", 'content found');
+$m->content_contains("<li>Zero 0 added</li>", 'zero field found');
 
 # http://issues.bestpractical.com/Ticket/Display.html?id=30378
 # #30378: RT 4.2.6 - Very long text fields get updated even when they haven't changed
@@ -71,5 +78,9 @@ $m->submit_form_ok({
 $m->content_contains('<li>TheControlField value a changed to value b</li>');
 $m->content_lacks("<li>TheTextarea $content changed to $content</li>", 'textarea wasnt updated');
 
+# http://issues.bestpractical.com/Ticket/Display.html?id=32440
+# #32440: Spurious "CF changed from 0 to 0"
+$m->content_lacks("<li>Zero 0 changed to 0</li>", "Zero wasn't updated");
+
 undef $m;
 done_testing;

commit 8810f2c4bab60fb9c76ab85144160c5bfc820bab
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Wed Nov 16 20:27:45 2016 +0000

    Avoid spurious "CF changed from 0 to 0" results
    
    Introduced in RT 4.2.9 with 724cf7f845cbdbb2e97c37d008a71ceba4f372a, a
    refactoring to address a similar spurious "CF changed from long value to
    long value" message (I#30378).
    
    That commit uses the old `($a || '') eq $b` idiom to avoid undef
    warnings, but when $a is the value "0", the "eq" operator produces a
    false negative, as `(0 || '') eq 0` is evaluated as `'' eq 0`, but the
    intent is that it should be true as `0 eq 0`. The modern // operator
    avoids the undef warnings but not at the expense of treating "0" in this
    broken way.
    
    Fixes: I#32440

diff --git a/lib/RT/ObjectCustomFieldValues.pm b/lib/RT/ObjectCustomFieldValues.pm
index b1cf3ca..1657f59 100644
--- a/lib/RT/ObjectCustomFieldValues.pm
+++ b/lib/RT/ObjectCustomFieldValues.pm
@@ -50,6 +50,7 @@ package RT::ObjectCustomFieldValues;
 
 use strict;
 use warnings;
+use 5.010;
 
 use base 'RT::SearchBuilder';
 
@@ -145,7 +146,7 @@ sub HasEntry {
             return $item if lc $item->Content eq lc $args->{Content};
         }
         else {
-            if ( ($item->_Value('Content') || '') eq $args->{Content} ) {
+            if ( ($item->_Value('Content') // '') eq $args->{Content} ) {
                 if ( defined $item->LargeContent ) {
                     return $item
                       if defined $args->{LargeContent}

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


More information about the rt-commit mailing list