From d9b3fdc3cbb164c1491d0966734bf9ff8d51454f Mon Sep 17 00:00:00 2001 From: Denis Pushkarev Date: Thu, 27 Jul 2023 03:14:40 +0700 Subject: [PATCH] fix a Chromium 117 bug in value argument of `URLSearchParams.prototype.{ has, delete }` https://bugs.chromium.org/p/v8/issues/detail?id=14222 --- CHANGELOG.md | 1 + .../internals/url-constructor-detection.js | 23 +++++++++++-------- .../modules/web.url-search-params.delete.js | 5 +++- .../modules/web.url-search-params.has.js | 4 +++- tests/compat/tests.js | 9 ++++++-- 5 files changed, 28 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 196fef2ad82a..b413479bb4ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,7 @@ - `DataView.prototype.getUint8Clamped` - `DataView.prototype.setUint8Clamped` - Used strict mode in some missed cases, [#1269](https://github.com/zloirock/core-js/issues/1269) +- Fixed [a Chromium 117 bug](https://bugs.chromium.org/p/v8/issues/detail?id=14222) in `value` argument of `URLSearchParams.prototype.{ has, delete }` - Fixed forced polyfilling of some iterator helpers that should return wrapped iterator in the pure version - Fixed and exposed [`AsyncIteratorPrototype` `core-js/configurator` option](https://github.com/zloirock/core-js#asynciterator-helpers), [#1268](https://github.com/zloirock/core-js/issues/1268) - Compat data improvements: diff --git a/packages/core-js/internals/url-constructor-detection.js b/packages/core-js/internals/url-constructor-detection.js index fe758168976a..fd828f8e7b0a 100644 --- a/packages/core-js/internals/url-constructor-detection.js +++ b/packages/core-js/internals/url-constructor-detection.js @@ -9,22 +9,25 @@ var ITERATOR = wellKnownSymbol('iterator'); module.exports = !fails(function () { // eslint-disable-next-line unicorn/relative-url-style -- required for testing var url = new URL('b?a=1&b=2&c=3', 'http://a'); - var searchParams = url.searchParams; - var searchParams2 = new URLSearchParams('a=1&a=2'); + var params = url.searchParams; + var params2 = new URLSearchParams('a=1&a=2&b=3'); var result = ''; url.pathname = 'c%20d'; - searchParams.forEach(function (value, key) { - searchParams['delete']('b'); + params.forEach(function (value, key) { + params['delete']('b'); result += key + value; }); - searchParams2['delete']('a', 2); - return (IS_PURE && (!url.toJSON || !searchParams2.has('a', 1) || searchParams2.has('a', 2))) - || (!searchParams.size && (IS_PURE || !DESCRIPTORS)) - || !searchParams.sort + params2['delete']('a', 2); + // `undefined` case is a Chromium 117 bug + // https://bugs.chromium.org/p/v8/issues/detail?id=14222 + params2['delete']('b', undefined); + return (IS_PURE && (!url.toJSON || !params2.has('a', 1) || params2.has('a', 2) || !params2.has('a', undefined) || params2.has('b'))) + || (!params.size && (IS_PURE || !DESCRIPTORS)) + || !params.sort || url.href !== 'http://a/c%20d?a=1&c=3' - || searchParams.get('c') !== '3' + || params.get('c') !== '3' || String(new URLSearchParams('?a=1')) !== 'a=1' - || !searchParams[ITERATOR] + || !params[ITERATOR] // throws in Edge || new URL('https://a@b').username !== 'a' || new URLSearchParams(new URLSearchParams('a=b')).get('a') !== 'b' diff --git a/packages/core-js/modules/web.url-search-params.delete.js b/packages/core-js/modules/web.url-search-params.delete.js index 172816eeb34a..0d8023a1a990 100644 --- a/packages/core-js/modules/web.url-search-params.delete.js +++ b/packages/core-js/modules/web.url-search-params.delete.js @@ -10,9 +10,12 @@ var append = uncurryThis(URLSearchParamsPrototype.append); var $delete = uncurryThis(URLSearchParamsPrototype['delete']); var forEach = uncurryThis(URLSearchParamsPrototype.forEach); var push = uncurryThis([].push); -var params = new $URLSearchParams('a=1&a=2'); +var params = new $URLSearchParams('a=1&a=2&b=3'); params['delete']('a', 1); +// `undefined` case is a Chromium 117 bug +// https://bugs.chromium.org/p/v8/issues/detail?id=14222 +params['delete']('b', undefined); if (params + '' !== 'a=2') { defineBuiltIn(URLSearchParamsPrototype, 'delete', function (name /* , value */) { diff --git a/packages/core-js/modules/web.url-search-params.has.js b/packages/core-js/modules/web.url-search-params.has.js index 90343173b511..46f6a2d52dfa 100644 --- a/packages/core-js/modules/web.url-search-params.has.js +++ b/packages/core-js/modules/web.url-search-params.has.js @@ -10,7 +10,9 @@ var getAll = uncurryThis(URLSearchParamsPrototype.getAll); var $has = uncurryThis(URLSearchParamsPrototype.has); var params = new $URLSearchParams('a=1'); -if (params.has('a', 2)) { +// `undefined` case is a Chromium 117 bug +// https://bugs.chromium.org/p/v8/issues/detail?id=14222 +if (params.has('a', 2) || !params.has('a', undefined)) { defineBuiltIn(URLSearchParamsPrototype, 'has', function has(name /* , value */) { var length = arguments.length; var $value = length < 2 ? undefined : arguments[1]; diff --git a/tests/compat/tests.js b/tests/compat/tests.js index a85f79a615b5..c3cd9ccb3d76 100644 --- a/tests/compat/tests.js +++ b/tests/compat/tests.js @@ -1973,13 +1973,18 @@ GLOBAL.tests = { }], 'web.url-search-params.constructor': URL_AND_URL_SEARCH_PARAMS_SUPPORT, 'web.url-search-params.delete': [URL_AND_URL_SEARCH_PARAMS_SUPPORT, function () { - var params = new URLSearchParams('a=1&a=2'); + var params = new URLSearchParams('a=1&a=2&b=3'); params['delete']('a', 1); + // `undefined` case is a Chromium 117 bug + // https://bugs.chromium.org/p/v8/issues/detail?id=14222 + params['delete']('b', undefined); return params + '' === 'a=2'; }], 'web.url-search-params.has': [URL_AND_URL_SEARCH_PARAMS_SUPPORT, function () { var params = new URLSearchParams('a=1'); - return params.has('a', 1) && !params.has('a', 2); + // `undefined` case is a Chromium 117 bug + // https://bugs.chromium.org/p/v8/issues/detail?id=14222 + return params.has('a', 1) && !params.has('a', 2) && params.has('a', undefined); }], 'web.url-search-params.size': [URL_AND_URL_SEARCH_PARAMS_SUPPORT, function () { return 'size' in URLSearchParams.prototype;