Skip to content

Commit a19a08d

Browse files
committed
switch to using stricter strict-uri-encode for uri encoding
1 parent 7bee64c commit a19a08d

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
var strictUriEncode = require('strict-uri-encode');
4+
35
exports.extract = function (maybeUrl) {
46
return maybeUrl.split('?')[1] || '';
57
};
@@ -43,10 +45,10 @@ exports.stringify = function (obj) {
4345

4446
if (Array.isArray(val)) {
4547
return val.sort().map(function (val2) {
46-
return encodeURIComponent(key) + '=' + encodeURIComponent(val2);
48+
return strictUriEncode(key) + '=' + strictUriEncode(val2);
4749
}).join('&');
4850
}
4951

50-
return encodeURIComponent(key) + '=' + encodeURIComponent(val);
52+
return strictUriEncode(key) + '=' + strictUriEncode(val);
5153
}).join('&') : '';
5254
};

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,8 @@
3535
},
3636
"engines": {
3737
"node": ">=0.10.0"
38+
},
39+
"dependencies": {
40+
"strict-uri-encode": "^1.0.0"
3841
}
3942
}

test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ describe('.stringify()', function () {
6262

6363
it('URI encode', function () {
6464
assert.strictEqual(qs.stringify({'foo bar': 'baz faz'}), 'foo%20bar=baz%20faz');
65+
assert.strictEqual(qs.stringify({'foo bar': "baz'faz"}), 'foo%20bar=baz%27faz');
6566
});
6667

6768
it('handle array value', function () {
@@ -88,4 +89,4 @@ describe('.extract()', function () {
8889
qs.extract(undefined);
8990
}, TypeError);
9091
});
91-
});
92+
});

0 commit comments

Comments
 (0)