qs 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/History.md +5 -0
- package/component.json +6 -0
- package/lib/querystring.js +17 -7
- package/package.json +1 -1
- package/test/parse.js +5 -3
package/History.md
CHANGED
package/component.json
ADDED
package/lib/querystring.js
CHANGED
|
@@ -99,12 +99,6 @@ function parseString(str){
|
|
|
99
99
|
return String(str)
|
|
100
100
|
.split('&')
|
|
101
101
|
.reduce(function(ret, pair){
|
|
102
|
-
try{
|
|
103
|
-
pair = decodeURIComponent(pair.replace(/\+/g, ' '));
|
|
104
|
-
} catch(e) {
|
|
105
|
-
// ignore
|
|
106
|
-
}
|
|
107
|
-
|
|
108
102
|
var eql = pair.indexOf('=')
|
|
109
103
|
, brace = lastBraceInKey(pair)
|
|
110
104
|
, key = pair.substr(0, brace || eql)
|
|
@@ -114,7 +108,7 @@ function parseString(str){
|
|
|
114
108
|
// ?foo
|
|
115
109
|
if ('' == key) key = pair, val = '';
|
|
116
110
|
|
|
117
|
-
return merge(ret, key, val);
|
|
111
|
+
return merge(ret, decode(key), decode(val));
|
|
118
112
|
}, { base: {} }).base;
|
|
119
113
|
}
|
|
120
114
|
|
|
@@ -250,3 +244,19 @@ function lastBraceInKey(str) {
|
|
|
250
244
|
if ('=' == c && !brace) return i;
|
|
251
245
|
}
|
|
252
246
|
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Decode `str`.
|
|
250
|
+
*
|
|
251
|
+
* @param {String} str
|
|
252
|
+
* @return {String}
|
|
253
|
+
* @api private
|
|
254
|
+
*/
|
|
255
|
+
|
|
256
|
+
function decode(str) {
|
|
257
|
+
try {
|
|
258
|
+
return decodeURIComponent(str.replace(/\+/g, ' '));
|
|
259
|
+
} catch (err) {
|
|
260
|
+
return str;
|
|
261
|
+
}
|
|
262
|
+
}
|
package/package.json
CHANGED
package/test/parse.js
CHANGED
|
@@ -28,9 +28,6 @@ describe('qs.parse()', function(){
|
|
|
28
28
|
expect(qs.parse('foo=bar'))
|
|
29
29
|
.to.eql({ foo: 'bar' });
|
|
30
30
|
|
|
31
|
-
expect(qs.parse('foo%3Dbar=baz'))
|
|
32
|
-
.to.eql({ foo: 'bar=baz' });
|
|
33
|
-
|
|
34
31
|
expect(qs.parse(' foo = bar = baz '))
|
|
35
32
|
.to.eql({ ' foo ': ' bar = baz ' });
|
|
36
33
|
|
|
@@ -52,6 +49,11 @@ describe('qs.parse()', function(){
|
|
|
52
49
|
});
|
|
53
50
|
})
|
|
54
51
|
|
|
52
|
+
it('should support encoded = signs', function(){
|
|
53
|
+
expect(qs.parse('he%3Dllo=th%3Dere'))
|
|
54
|
+
.to.eql({ 'he=llo': 'th=ere' });
|
|
55
|
+
})
|
|
56
|
+
|
|
55
57
|
it('should support nesting', function(){
|
|
56
58
|
expect(qs.parse('ops[>=]=25'))
|
|
57
59
|
.to.eql({ ops: { '>=': '25' }});
|