From 59356becea4d24ee57b766ff632d5f09443dd7ee Mon Sep 17 00:00:00 2001 From: guanbo Date: Wed, 21 Aug 2013 16:42:02 +0800 Subject: [PATCH 1/3] Fixed: format multilevel json to querystring correctly --- bower.json | 4 ++-- src/ng/http.js | 40 ++++++++++++++++++++++++++++------------ test/ng/httpSpec.js | 2 +- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/bower.json b/bower.json index 65a383deb67b..f8744724b309 100644 --- a/bower.json +++ b/bower.json @@ -5,8 +5,8 @@ "lunr.js": "0.4.0", "google-code-prettify": "1.0.0", "components-font-awesome": "3.1.0", - "bootstrap": "https://raw.github.com/twbs/bootstrap/v2.0.2/docs/assets/bootstrap.zip", + "bootstrap": "2.0.2", "closure-compiler": "https://closure-compiler.googlecode.com/files/compiler-20130603.zip", - "ng-closure-runner": "https://raw.github.com/angular/ng-closure-runner/v0.2.2/assets/ng-closure-runner.zip" + "ng-closure-runner": "https://github.com/angular/ng-closure-runner/archive/v0.2.2.zip" } } diff --git a/src/ng/http.js b/src/ng/http.js index f76f1cff25b8..3dbd3a65b634 100644 --- a/src/ng/http.js +++ b/src/ng/http.js @@ -963,22 +963,38 @@ function $HttpProvider() { } } + function is(type, obj) { + var clas = Object.prototype.toString.call(obj).slice(8, -1); + return obj !== undefined && obj !== null && clas === type; + } + + function toQueryString(params, parts, pk) { + forEachSorted(params, function(value, key) { + if (value == null || value == undefined) return; + if (pk) key = pk+'['+key+']' + if (is('Array',value)) { + forEach(value, function(v,i) { + if(is('Object', v)){ + key = key+'['+i+']' + toQueryString(v, parts, key) + } else { + parts.push(encodeUriQuery(key) + '=' + + encodeUriQuery(v)); + } + }); + return; + } else if (is('Object',value)) { + return toQueryString(value, parts, key) + } + parts.push(encodeUriQuery(key) + '=' + + encodeUriQuery(value)); + }); + } function buildUrl(url, params) { if (!params) return url; var parts = []; - forEachSorted(params, function(value, key) { - if (value == null || value == undefined) return; - if (!isArray(value)) value = [value]; - - forEach(value, function(v) { - if (isObject(v)) { - v = toJson(v); - } - parts.push(encodeUriQuery(key) + '=' + - encodeUriQuery(v)); - }); - }); + toQueryString(params, parts) return url + ((url.indexOf('?') == -1) ? '?' : '&') + parts.join('&'); } diff --git a/test/ng/httpSpec.js b/test/ng/httpSpec.js index ec1cb7f1cb2c..eb190ee5076a 100644 --- a/test/ng/httpSpec.js +++ b/test/ng/httpSpec.js @@ -432,7 +432,7 @@ describe('$http', function() { it('should jsonify objects in params map', inject(function($httpBackend, $http) { - $httpBackend.expect('GET', '/url?a=1&b=%7B%22c%22:3%7D').respond(''); + $httpBackend.expect('GET', '/url?a=1&b%5Bc%5D=3').respond(''); $http({url: '/url', params: {a:1, b:{c:3}}, method: 'GET'}); })); From 462609a47a186731ebb5956f6c05a5d64418e9ea Mon Sep 17 00:00:00 2001 From: guanbo Date: Thu, 22 Aug 2013 11:51:07 +0800 Subject: [PATCH 2/3] Fixed: bower for pass travis --- bower.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bower.json b/bower.json index f8744724b309..65a383deb67b 100644 --- a/bower.json +++ b/bower.json @@ -5,8 +5,8 @@ "lunr.js": "0.4.0", "google-code-prettify": "1.0.0", "components-font-awesome": "3.1.0", - "bootstrap": "2.0.2", + "bootstrap": "https://raw.github.com/twbs/bootstrap/v2.0.2/docs/assets/bootstrap.zip", "closure-compiler": "https://closure-compiler.googlecode.com/files/compiler-20130603.zip", - "ng-closure-runner": "https://github.com/angular/ng-closure-runner/archive/v0.2.2.zip" + "ng-closure-runner": "https://raw.github.com/angular/ng-closure-runner/v0.2.2/assets/ng-closure-runner.zip" } } From 7c17674c5fa8834b1bfaf1b372ed9e4bbd76e07f Mon Sep 17 00:00:00 2001 From: guanbo Date: Wed, 11 Sep 2013 14:36:00 +0800 Subject: [PATCH 3/3] =?UTF-8?q?Fixed=EF=BC=9AAdd=20semicolon=20to=20follow?= =?UTF-8?q?ing=20google's=20javascript=20style?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ng/http.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ng/http.js b/src/ng/http.js index 3dbd3a65b634..e51c1ff92c13 100644 --- a/src/ng/http.js +++ b/src/ng/http.js @@ -971,11 +971,11 @@ function $HttpProvider() { function toQueryString(params, parts, pk) { forEachSorted(params, function(value, key) { if (value == null || value == undefined) return; - if (pk) key = pk+'['+key+']' + if (pk) key = pk+'['+key+']'; if (is('Array',value)) { forEach(value, function(v,i) { if(is('Object', v)){ - key = key+'['+i+']' + key = key+'['+i+']'; toQueryString(v, parts, key) } else { parts.push(encodeUriQuery(key) + '=' + @@ -994,7 +994,7 @@ function $HttpProvider() { function buildUrl(url, params) { if (!params) return url; var parts = []; - toQueryString(params, parts) + toQueryString(params, parts); return url + ((url.indexOf('?') == -1) ? '?' : '&') + parts.join('&'); }