diff options
| author | Igor Minar | 2013-01-21 22:00:15 -0800 | 
|---|---|---|
| committer | Igor Minar | 2013-01-22 07:35:06 -0800 | 
| commit | c7addd488677307c6d2b35c7656179fbe6d80999 (patch) | |
| tree | 1be49a5798c66c62afbc4d7752159a9e3572cc88 /src | |
| parent | 6df60aff527e1ae13815a14fe3994b471e623a5b (diff) | |
| download | angular.js-c7addd488677307c6d2b35c7656179fbe6d80999.tar.bz2 | |
fix(angular.equals): relax the comparison for undefined properties
in 5ae63fd3 the comparison was made consistent but strict, so that
angular.equals({}, {foo: undefined}) // always returns false
this turns out to cause issues for data that is being roundtripped via network
and serialized via JSON because JSON.stringify serializes {foo: undefined} as {}.
Since angular.equals() behaved like this before the 5ae63fd3 in 50% of the cases,
changing the behavior in this way should not introduce any significant issues.
Closes #1648
Diffstat (limited to 'src')
| -rw-r--r-- | src/Angular.js | 19 | 
1 files changed, 7 insertions, 12 deletions
diff --git a/src/Angular.js b/src/Angular.js index 21b3ef07..a7b3b98c 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -620,23 +620,18 @@ function equals(o1, o2) {        } else {          if (isScope(o1) || isScope(o2) || isWindow(o1) || isWindow(o2)) return false;          keySet = {}; -        length = 0;          for(key in o1) { -          if (key.charAt(0) === '$') continue; - -          if (!isFunction(o1[key]) && !equals(o1[key], o2[key])) return false; - -          length++; +          if (key.charAt(0) === '$' || isFunction(o1[key])) continue; +          if (!equals(o1[key], o2[key])) return false;            keySet[key] = true;          }          for(key in o2) { -          if (key.charAt(0) === '$') { -            continue; -          } -          if (!keySet[key] && !isFunction(o2[key])) return false; -          length--; +          if (!keySet[key] && +              key.charAt(0) !== '$' && +              o2[key] !== undefined && +              !isFunction(o2[key])) return false;          } -        return length === 0; +        return true;        }      }    }  | 
