Skip to content

Commit 593d4c5

Browse files
go-olegkevva
authored andcommitted
Use stricter URI encoding
Fixes #29.
1 parent 7bee64c commit 593d4c5

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict';
2+
var strictUriEncode = require('strict-uri-encode');
23

34
exports.extract = function (maybeUrl) {
45
return maybeUrl.split('?')[1] || '';
@@ -43,10 +44,10 @@ exports.stringify = function (obj) {
4344

4445
if (Array.isArray(val)) {
4546
return val.sort().map(function (val2) {
46-
return encodeURIComponent(key) + '=' + encodeURIComponent(val2);
47+
return strictUriEncode(key) + '=' + strictUriEncode(val2);
4748
}).join('&');
4849
}
4950

50-
return encodeURIComponent(key) + '=' + encodeURIComponent(val);
51+
return strictUriEncode(key) + '=' + strictUriEncode(val);
5152
}).join('&') : '';
5253
};

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
"scripts": {
3131
"test": "mocha"
3232
},
33+
"dependencies": {
34+
"strict-uri-encode": "^1.0.0"
35+
},
3336
"devDependencies": {
3437
"mocha": "*"
3538
},

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)