diff options
| author | Caitlin Potter | 2013-12-18 23:52:31 -0500 | 
|---|---|---|
| committer | Igor Minar | 2013-12-19 00:59:22 -0800 | 
| commit | 26d43cacdc106765bd928d41600352198f887aef (patch) | |
| tree | d2dcaffd0b6fa1b020102921ee49226c8c849b7f /test/ng/parseSpec.js | |
| parent | 4f5758e6669222369889c9e789601d25ff885530 (diff) | |
| download | angular.js-26d43cacdc106765bd928d41600352198f887aef.tar.bz2 | |
fix($parse): return 'undefined' if a middle key's value is null
Prior to this fix, $parse/$eval would return 'null' if a middle key in
an expression's value is null, when it should be expected to be undefined.
This patch tries to remedy this by returning undefined for middle values in
expressions, when fetching a child of that null value.
For example:
```js
// Given the following object:
$scope.a = {
  b: null
};
// $scope.$eval('a.b.c') returns undefined, whereas previously it would return null
```
Closes #5480
Diffstat (limited to 'test/ng/parseSpec.js')
| -rw-r--r-- | test/ng/parseSpec.js | 49 | 
1 files changed, 49 insertions, 0 deletions
| diff --git a/test/ng/parseSpec.js b/test/ng/parseSpec.js index 5e985f1f..4599c033 100644 --- a/test/ng/parseSpec.js +++ b/test/ng/parseSpec.js @@ -977,6 +977,55 @@ describe('parser', function() {              expect($parse('"name" + id').constant).toBe(false);            }));          }); + +        describe('nulls in expressions', function() { +          // simpleGetterFn1 +          it('should return null for `a` where `a` is null', inject(function($rootScope) { +            $rootScope.a = null; +            expect($rootScope.$eval('a')).toBe(null); +          })); + +          it('should return undefined for `a` where `a` is undefined', inject(function($rootScope) { +            expect($rootScope.$eval('a')).toBeUndefined(); +          })); + +          // simpleGetterFn2 +          it('should return undefined for properties of `null` constant', inject(function($rootScope) { +            expect($rootScope.$eval('null.a')).toBeUndefined(); +          })); + +          it('should return undefined for properties of `null` values', inject(function($rootScope) { +            $rootScope.a = null; +            expect($rootScope.$eval('a.b')).toBeUndefined(); +          })); + +          it('should return null for `a.b` where `b` is null', inject(function($rootScope) { +            $rootScope.a = { b: null }; +            expect($rootScope.$eval('a.b')).toBe(null); +          })); + +          // cspSafeGetter && pathKeys.length < 6 || pathKeys.length > 2 +          it('should return null for `a.b.c.d.e` where `e` is null', inject(function($rootScope) { +            $rootScope.a = { b: { c: { d: { e: null } } } }; +            expect($rootScope.$eval('a.b.c.d.e')).toBe(null); +          })); + +          it('should return undefined for `a.b.c.d.e` where `d` is null', inject(function($rootScope) { +            $rootScope.a = { b: { c: { d: null } } }; +            expect($rootScope.$eval('a.b.c.d.e')).toBeUndefined(); +          })); + +          // cspSafeGetter || pathKeys.length > 6 +          it('should return null for `a.b.c.d.e.f.g` where `g` is null', inject(function($rootScope) { +            $rootScope.a = { b: { c: { d: { e: { f: { g: null } } } } } }; +            expect($rootScope.$eval('a.b.c.d.e.f.g')).toBe(null); +          })); + +          it('should return undefined for `a.b.c.d.e.f.g` where `f` is null', inject(function($rootScope) { +            $rootScope.a = { b: { c: { d: { e: { f: null } } } } }; +            expect($rootScope.$eval('a.b.c.d.e.f.g')).toBeUndefined(); +          })); +        });        });      });    }); | 
