diff options
| author | Igor Minar | 2010-12-22 13:19:26 -0800 |
|---|---|---|
| committer | Igor Minar | 2010-12-22 14:16:36 -0800 |
| commit | e7a0fb250f6cc69c93daffe0d043d073fd488c03 (patch) | |
| tree | a799e9264a131a9124de7983b5655b9e97df44ba /test/JsonSpec.js | |
| parent | e3ddc2bcc48ba6160455c4ffe35df87715c05693 (diff) | |
| download | angular.js-e7a0fb250f6cc69c93daffe0d043d073fd488c03.tar.bz2 | |
fromJson delegation to native JSON parser if available
- native parser delegation
- $xhr change to use native parser
Diffstat (limited to 'test/JsonSpec.js')
| -rw-r--r-- | test/JsonSpec.js | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/test/JsonSpec.js b/test/JsonSpec.js index ba3366e5..6d8a40e4 100644 --- a/test/JsonSpec.js +++ b/test/JsonSpec.js @@ -116,6 +116,42 @@ describe('json', function(){ expect(fromJson("{exp:1.2e-10}")).toEqual({exp:1.2E-10}); }); + + //run these tests only in browsers that have native JSON parser + if (JSON && JSON.parse) { + + describe('native parser', function() { + + var nativeParser = JSON.parse; + + afterEach(function() { + JSON.parse = nativeParser; + }); + + + it('should delegate to native parser if available and boolean flag is passed', function() { + var spy = this.spyOn(JSON, 'parse').andCallThrough(); + + expect(fromJson('{}')).toEqual({}); + expect(spy).wasNotCalled(); + + expect(fromJson('{}', true)).toEqual({}); + expect(spy).wasCalled(); + }); + + + it('should convert timestamp strings to Date objects', function() { + expect(fromJson('"2010-12-22T17:23:17.974Z"', true) instanceof Date).toBe(true); + expect(fromJson('["2010-12-22T17:23:17.974Z"]', true)[0] instanceof Date).toBe(true); + expect(fromJson('{"t":"2010-12-22T17:23:17.974Z"}', true).t instanceof Date).toBe(true); + expect(fromJson('{"t":["2010-12-22T17:23:17.974Z"]}', true).t[0] instanceof Date).toBe(true); + expect(fromJson('{"t":{"t":"2010-12-22T17:23:17.974Z"}}', true).t.t instanceof Date).toBe(true); + }); + }); + + } + + describe('security', function(){ it('should not allow naked expressions', function(){ expect(function(){fromJson('1+2');}). |
