diff options
| author | Igor Minar | 2011-03-31 21:45:28 -0700 |
|---|---|---|
| committer | Igor Minar | 2011-03-31 21:45:28 -0700 |
| commit | 78a0f41058a3c8094cf3b8979baa212a3b88b2a6 (patch) | |
| tree | 65ea56de5dc593a7897c36ede315960db5d129fb /test | |
| parent | eccd9bfbb3d63731814941789089e1c799005fb4 (diff) | |
| download | angular.js-78a0f41058a3c8094cf3b8979baa212a3b88b2a6.tar.bz2 | |
encode query params correctly but not too agressively
Diffstat (limited to 'test')
| -rw-r--r-- | test/AngularSpec.js | 33 | ||||
| -rw-r--r-- | test/ResourceSpec.js | 6 |
2 files changed, 34 insertions, 5 deletions
diff --git a/test/AngularSpec.js b/test/AngularSpec.js index 61dc7cfc..9b3357e5 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -55,7 +55,6 @@ describe('angular', function(){ expect(copy(123)).toEqual(123); expect(copy([{key:null}])).toEqual([{key:null}]); }); - }); describe('equals', function(){ @@ -170,7 +169,7 @@ describe('angular', function(){ describe('encodeUriSegment', function() { - it('should correctly encode uri segment and not encode chars defined as pchar set in rfc2396', + it('should correctly encode uri segment and not encode chars defined as pchar set in rfc3986', function() { //don't encode alphanum expect(encodeUriSegment('asdf1234asdf')). @@ -191,6 +190,36 @@ describe('angular', function(){ }); + describe('encodeUriQuery', function() { + it('should correctly encode uri query and not encode chars defined as pchar set in rfc3986', + function() { + //don't encode alphanum + expect(encodeUriQuery('asdf1234asdf')). + toEqual('asdf1234asdf'); + + //don't encode unreserved + expect(encodeUriQuery("-_.!~*'() -_.!~*'()")). + toEqual("-_.!~*'()+-_.!~*'()"); + + //don't encode the rest of pchar + expect(encodeUriQuery(':@$, :@$,')). + toEqual(':@$,+:@$,'); + + //encode '&', ';', '=', '+', and '#' + expect(encodeUriQuery('&;=+# &;=+#')). + toEqual('%26%3B%3D%2B%23+%26%3B%3D%2B%23'); + + //encode ' ' as '+' + expect(encodeUriQuery(' ')). + toEqual('++'); + + //encode ' ' as '%20' when a flag is used + expect(encodeUriQuery(' ', true)). + toEqual('%20%20'); + }); + }); + + describe ('rngScript', function() { it('should match angular.js', function() { expect('angular.js'.match(rngScript)).not.toBeNull(); diff --git a/test/ResourceSpec.js b/test/ResourceSpec.js index 663b163d..e055beab 100644 --- a/test/ResourceSpec.js +++ b/test/ResourceSpec.js @@ -49,14 +49,14 @@ describe("resource", function() { }); it('should not encode @ in url params', function() { - //encodeURIComponent is too agressive and doesn't follow http://www.ietf.org/rfc/rfc2396.txt + //encodeURIComponent is too agressive and doesn't follow http://www.ietf.org/rfc/rfc3986.txt //with regards to the character set (pchar) allowed in path segments //so we need this test to make sure that we don't over-encode the params and break stuff like //buzz api which uses @self var R = resource.route('/Path/:a'); - xhr.expectGET('/Path/doh@foo?bar=baz%401').respond({}); - R.get({a: 'doh@foo', bar: 'baz@1'}); + xhr.expectGET('/Path/doh@fo%20o?!do%26h=g%3Da+h&:bar=$baz@1').respond({}); + R.get({a: 'doh@fo o', ':bar': '$baz@1', '!do&h': 'g=a h'}); }); it('should encode & in url params', function() { |
