From 67291bb9faa5c0a8739bd5392e60f680fb08bdb3 Mon Sep 17 00:00:00 2001 From: Benjamin Dreux Date: Fri, 12 Sep 2014 08:02:42 -0400 Subject: [PATCH 1/2] Add support complexe object into queryParams convert each value candidate to string params into a json string before go into encoreURIComponent Used JSON.stringify, which according to http://caniuse.com/#search=JSON is available in every browser without restriction since IE9 Added test for that, but can't run them since there is missing parts for running them from the sources --- core-xhr.html | 8 ++++---- tests/html/core-ajax.html | 37 ++++++++++++++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/core-xhr.html b/core-xhr.html index 8557aec..1012f9f 100644 --- a/core-xhr.html +++ b/core-xhr.html @@ -71,12 +71,12 @@ } return xhr; }, - + toQueryString: function(params) { var r = []; for (var n in params) { var v = params[n]; - n = encodeURIComponent(n); + n = encodeURIComponent(JSON.stringify(n)); r.push(v == null ? n : (n + '=' + encodeURIComponent(v))); } return r.join('&'); @@ -85,7 +85,7 @@ isBodyMethod: function(method) { return this.bodyMethods[(method || '').toUpperCase()]; }, - + bodyMethods: { POST: 1, PUT: 1, @@ -111,5 +111,5 @@ }); - + diff --git a/tests/html/core-ajax.html b/tests/html/core-ajax.html index 6f14152..0b028d1 100644 --- a/tests/html/core-ajax.html +++ b/tests/html/core-ajax.html @@ -21,20 +21,51 @@ + auto> + + + + + + + From 8d80ec0e55628d210d3ec379cb2ab2284394a585 Mon Sep 17 00:00:00 2001 From: Benjamin Dreux Date: Fri, 12 Sep 2014 09:35:34 -0400 Subject: [PATCH 2/2] really add support for complexe object Separate tests for neasted object and arrays into distinct files correct xhr parm encoding --- core-xhr.html | 14 +++++-- tests/html/core-ajax-arrays.html | 47 +++++++++++++++++++++++ tests/html/core-ajax-complexe-object.html | 44 +++++++++++++++++++++ tests/html/core-ajax.html | 29 ++++---------- tests/js/htmltests.js | 4 +- 5 files changed, 113 insertions(+), 25 deletions(-) create mode 100644 tests/html/core-ajax-arrays.html create mode 100644 tests/html/core-ajax-complexe-object.html diff --git a/core-xhr.html b/core-xhr.html index 1012f9f..058da39 100644 --- a/core-xhr.html +++ b/core-xhr.html @@ -76,12 +76,20 @@ var r = []; for (var n in params) { var v = params[n]; - n = encodeURIComponent(JSON.stringify(n)); - r.push(v == null ? n : (n + '=' + encodeURIComponent(v))); + n = encodeURIComponent(n); + if(v == null){ + r.push(n); + }else{ + v = this.isString(v) ? v : JSON.stringify(v); + r.push(n + '=' + encodeURIComponent(v)); + } } return r.join('&'); }, - + isString:function(str){ + return str instanceof String || + typeof str === 'string'; + }, isBodyMethod: function(method) { return this.bodyMethods[(method || '').toUpperCase()]; }, diff --git a/tests/html/core-ajax-arrays.html b/tests/html/core-ajax-arrays.html new file mode 100644 index 0000000..104d1c1 --- /dev/null +++ b/tests/html/core-ajax-arrays.html @@ -0,0 +1,47 @@ + + + + + core-ajax + + + + + + + + + + + + + + + + + diff --git a/tests/html/core-ajax-complexe-object.html b/tests/html/core-ajax-complexe-object.html new file mode 100644 index 0000000..bd07743 --- /dev/null +++ b/tests/html/core-ajax-complexe-object.html @@ -0,0 +1,44 @@ + + + + + core-ajax + + + + + + + + + + + + + + + + diff --git a/tests/html/core-ajax.html b/tests/html/core-ajax.html index 0b028d1..3f63541 100644 --- a/tests/html/core-ajax.html +++ b/tests/html/core-ajax.html @@ -27,22 +27,14 @@ handleAs="json" auto> - - - - +