diff options
| author | Igor Minar | 2011-03-02 17:29:38 -0800 | 
|---|---|---|
| committer | Igor Minar | 2011-03-02 22:56:14 -0800 | 
| commit | cd139f57678b98c82387d5b0034f653043b7165a (patch) | |
| tree | 4c96599f8f94f6a69ef478e4d97d46bd7575920a /test/service/xhrSpec.js | |
| parent | 10a7521f0b4f86b800d43f6276ee6f0c1c396129 (diff) | |
| download | angular.js-cd139f57678b98c82387d5b0034f653043b7165a.tar.bz2 | |
$xhr service now autodetects and strips )]}',\n
")]}\',\n" is a commonly used security prefix added to json http
responses iat google and elsewhere in order to prevent certain
cross-site attacks
$xhr service now autodetects the prefix and strips it before
deserializing the json.
the implementation should be more flexible to allow for wider range
of prefixes, but we need this one right now and can address other
usecases later.
Diffstat (limited to 'test/service/xhrSpec.js')
| -rw-r--r-- | test/service/xhrSpec.js | 39 | 
1 files changed, 39 insertions, 0 deletions
| diff --git a/test/service/xhrSpec.js b/test/service/xhrSpec.js index 35861a92..fc51eff2 100644 --- a/test/service/xhrSpec.js +++ b/test/service/xhrSpec.js @@ -44,4 +44,43 @@ describe('$xhr', function() {      expect($log.error).wasCalledWith("MyException");    }); + + +  it('should automatically deserialize json objects', function() { +    var response; + +    $browserXhr.expectGET('/foo').respond('{"foo":"bar","baz":23}'); +    $xhr('GET', '/foo', function(code, resp) { +      response = resp; +    }); +    $browserXhr.flush(); + +    expect(response).toEqual({foo:'bar', baz:23}); +  }); + + +  it('should automatically deserialize json arrays', function() { +    var response; + +    $browserXhr.expectGET('/foo').respond('[1, "abc", {"foo":"bar"}]'); +    $xhr('GET', '/foo', function(code, resp) { +      response = resp; +    }); +    $browserXhr.flush(); + +    expect(response).toEqual([1, 'abc', {foo:'bar'}]); +  }); + + +  it('should automatically deserialize json with security prefix', function() { +    var response; + +    $browserXhr.expectGET('/foo').respond(')]}\',\n[1, "abc", {"foo":"bar"}]'); +    $xhr('GET', '/foo', function(code, resp) { +      response = resp; +    }); +    $browserXhr.flush(); + +    expect(response).toEqual([1, 'abc', {foo:'bar'}]); +  });  }); | 
