Skip to content

Commit

Permalink
Decode query string which has special characters. Fixed #38
Browse files Browse the repository at this point in the history
  • Loading branch information
jerrybendy committed Apr 26, 2019
1 parent 520ea10 commit cb66794
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,11 @@
}

function decode(str) {
return decodeURIComponent(str.replace(/\+/g, ' '));
return str
.replace(/[ +]/g, '%20')
.replace(/(%[a-f0-9]{2})+/ig, function(match) {
return decodeURIComponent(match);
});
}

function makeIterator(arr) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "url-search-params-polyfill",
"version": "5.1.0",
"version": "6.0.0",
"description": "a simple polyfill for javascript URLSearchParams",
"homepage": "https://github.com/jerrybendy/url-search-params-polyfill",
"main": "index.js",
Expand Down
5 changes: 3 additions & 2 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,11 @@ describe(PREFIX + 'Others', function () {
b: '<script>',
c: 'http://a.com/?c=7&d=8#!/asd',
d: 'hello world',
e: '+'
e: '+',
f: '/%^^%zz%%%world你好'
};

var testStr = 'a=%E4%BD%A0%E5%A5%BD&b=%3Cscript%3E&c=http%3A%2F%2Fa.com%2F%3Fc%3D7%26d%3D8%23%21%2Fasd&d=hello+world&e=%2B';
var testStr = 'a=%E4%BD%A0%E5%A5%BD&b=%3Cscript%3E&c=http%3A%2F%2Fa.com%2F%3Fc%3D7%26d%3D8%23%21%2Fasd&d=hello+world&e=%2B&f=%2F%25%5E%5E%25zz%25%25%25world%E4%BD%A0%E5%A5%BD';

it('URL encode', function () {
var a = new URLSearchParams(testObj);
Expand Down

0 comments on commit cb66794

Please sign in to comment.