diff --git a/index.js b/index.js index 25333df2..0aca0dc8 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,7 @@ 'use strict'; +var strictUriEncode = require('strict-uri-encode'); + exports.extract = function (maybeUrl) { return maybeUrl.split('?')[1] || ''; }; @@ -43,10 +45,10 @@ exports.stringify = function (obj) { if (Array.isArray(val)) { return val.sort().map(function (val2) { - return encodeURIComponent(key) + '=' + encodeURIComponent(val2); + return strictUriEncode(key) + '=' + strictUriEncode(val2); }).join('&'); } - return encodeURIComponent(key) + '=' + encodeURIComponent(val); + return strictUriEncode(key) + '=' + strictUriEncode(val); }).join('&') : ''; }; diff --git a/package.json b/package.json index e193a9a1..63eceddc 100644 --- a/package.json +++ b/package.json @@ -35,5 +35,8 @@ }, "engines": { "node": ">=0.10.0" + }, + "dependencies": { + "strict-uri-encode": "^1.0.0" } } diff --git a/test.js b/test.js index 32d5ba9c..a84a5ddb 100644 --- a/test.js +++ b/test.js @@ -62,6 +62,7 @@ describe('.stringify()', function () { it('URI encode', function () { assert.strictEqual(qs.stringify({'foo bar': 'baz faz'}), 'foo%20bar=baz%20faz'); + assert.strictEqual(qs.stringify({'foo bar': "baz'faz"}), 'foo%20bar=baz%27faz'); }); it('handle array value', function () { @@ -88,4 +89,4 @@ describe('.extract()', function () { qs.extract(undefined); }, TypeError); }); -}); \ No newline at end of file +});