From cb66794b60f603dd35e71e3031f2479e678a78c8 Mon Sep 17 00:00:00 2001 From: Jerry Bendy Date: Fri, 26 Apr 2019 14:28:33 +0800 Subject: [PATCH] Decode query string which has special characters. Fixed #38 --- index.js | 6 +++++- package.json | 2 +- test/index.test.js | 5 +++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 6af93a9..8b2cc41 100644 --- a/index.js +++ b/index.js @@ -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) { diff --git a/package.json b/package.json index cd06347..8d1cba9 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/index.test.js b/test/index.test.js index 5e2d6d4..97caf01 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -262,10 +262,11 @@ describe(PREFIX + 'Others', function () { b: '