Uploaded image for project: 'Z-Push'
  1. Z-Push
  2. ZP-1229

Strict type checking in SyncObject.equals() may break other backends

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Medium
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.3.7 beta1, 2.3.7
    • Component/s: None
    • Labels:
      None

      Description

      A change made in ZP-1088 to require strict type checking on properties of objects breaks backend comparisons.

      if ($this->$val != $odo->$val){

      in Syncobject.equals() was changed to

      if ($this->$val !== $odo->$val){

      While the wbxmlencoder does not care if an integer value or a string value is passed to it, and the prior code would allow objects to be matched regardless of which type of value was in either object, then changed code breaks if the data types do not match.

      A sample log message generated by the zimbra backend that shows the problem is

      31/05/2017 12:45:58 [ 5670] [DEBUG] [myUser] [myDevice] SyncObject->equals() false on field 'type': '1' != '1'

      The comparison of two values that are the same is breaking because one has been read from the backend as an integer, while the one passed in from the device has been decoded as a string.

      Suggested fix is to add an extra optional parameter to specify when an exact type match is needed.

      It looks like it was added for ZP-1088 for a specific case of detecting a parent folder Id change.

      If that is the only place that type safety matters, that be accommodated by the addition of an extra optional parameter on the equals() function which defaults to false.

      public function equals($odo, $log = false, $strictTypeCompare = false) {

      ....
      if ($strictTypeCompare && ($this->$val !== $odo->$val))

      { ZLog::Write(LOGLEVEL_DEBUG, sprintf("SyncObject->equals() false on field '%s': '%s' != '%s'", $val, Utils::PrintAsString($this->$val), Utils::PrintAsString($odo->$val))); return false; }

      elseif ($this->$val != $odo->$val)

      { ZLog::Write(LOGLEVEL_DEBUG, sprintf("SyncObject->equals() false on field '%s': '%s' != '%s'", $val, Utils::PrintAsString($this->$val), Utils::PrintAsString($odo->$val))); return false; }

      This would avoid the necessity to do a lot of retrofitting on backends

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  Sebastian Sebastian Kummer
                  Reporter:
                  liverpoolfcfan Vincent Sherwood
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  1 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:

                    Time Tracking

                    Estimated:
                    Original Estimate - Not Specified
                    Not Specified
                    Remaining:
                    Remaining Estimate - 0 minutes
                    0m
                    Logged:
                    Time Spent - 20 minutes
                    20m