Skip to content

Commit

Permalink
Percent decode
Browse files Browse the repository at this point in the history
  • Loading branch information
slowcheetah committed Aug 12, 2024
1 parent c48c4ec commit 485c871
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 14 deletions.
18 changes: 4 additions & 14 deletions packages/core-js/modules/web.url-search-params.constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ var validateArgumentsLength = require('../internals/validate-arguments-length');
var wellKnownSymbol = require('../internals/well-known-symbol');
var arraySort = require('../internals/array-sort');

var $includes = require('../internals/array-includes').includes;

var ITERATOR = wellKnownSymbol('iterator');
var URL_SEARCH_PARAMS = 'URLSearchParams';
var URL_SEARCH_PARAMS_ITERATOR = URL_SEARCH_PARAMS + 'Iterator';
Expand All @@ -60,7 +58,6 @@ var stringSlice = uncurryThis(''.slice);

var FALLBACK_REPLACER = '\uFFFD';
var charCodeAt = uncurryThis(''.charCodeAt);
var substring = uncurryThis(''.substring);
var indexOf = uncurryThis(''.indexOf);
var fromCharCode = String.fromCharCode;
var fromCodePoint = getBuiltIn('String', 'fromCodePoint');
Expand Down Expand Up @@ -98,7 +95,7 @@ var utf8Decode = function (octets) {
};

/* eslint-disable max-statements -- TODO */
var decode = function (input, preserveEscapeSet) {
var decode = function (input) {
var length = input.length;
var result = '';
var i = 0;
Expand All @@ -113,7 +110,6 @@ var decode = function (input, preserveEscapeSet) {
break;
}

var escapeSequence = substring(input, i, i + 3);
var octet = parseHexOctet(input, i + 1);

if (isNaN(octet)) {
Expand All @@ -126,8 +122,7 @@ var decode = function (input, preserveEscapeSet) {
var byteSequenceLength = getLeadingOnes(octet);

if (byteSequenceLength === 0) {
var asciiChar = fromCharCode(octet);
decodedChar = $includes(preserveEscapeSet, asciiChar, undefined) ? escapeSequence : asciiChar;
decodedChar = fromCharCode(octet);
} else {
if (byteSequenceLength === 1 || byteSequenceLength > 4) {
result += FALLBACK_REPLACER;
Expand Down Expand Up @@ -180,11 +175,6 @@ var decode = function (input, preserveEscapeSet) {
return result;
};

var deserialize = function (it) {
var preserveEscapeSet = ['%', ';', '/', '?', ':', '@', '&', '=', '+', '$', ',', '#'];
return decode(it, preserveEscapeSet);
};

var find = /[!'()~]|%20/g;

var replacements = {
Expand Down Expand Up @@ -275,8 +265,8 @@ URLSearchParamsState.prototype = {
if (attribute.length) {
entry = split(attribute, '=');
push(entries, {
key: deserialize(shift(entry)),
value: deserialize(join(entry, '='))
key: decode(shift(entry)),
value: decode(join(entry, '='))
});
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/unit-global/web.url-search-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ QUnit.test('URLSearchParams', assert => {

assert.same(String(new URLSearchParams('%C2')), '%EF%BF%BD=');
assert.same(String(new URLSearchParams('%F0%9F%D0%90')), '%EF%BF%BD%D0%90=');
assert.same(String(new URLSearchParams('%25')), '%25=');

const testData = [
{ input: '?a=%', output: [['a', '%']], name: 'handling %' },
Expand Down
1 change: 1 addition & 0 deletions tests/unit-pure/web.url-search-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ QUnit.test('URLSearchParams', assert => {

assert.same(String(new URLSearchParams('%C2')), '%EF%BF%BD=');
assert.same(String(new URLSearchParams('%F0%9F%D0%90')), '%EF%BF%BD%D0%90=');
assert.same(String(new URLSearchParams('%25')), '%25=');

const testData = [
{ input: '?a=%', output: [['a', '%']], name: 'handling %' },
Expand Down

0 comments on commit 485c871

Please sign in to comment.