Skip to content

Commit

Permalink
fix a Chromium 117 bug in value argument of `URLSearchParams.prototyp…
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Jul 26, 2023
1 parent ce17c76 commit d9b3fdc
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
23 changes: 13 additions & 10 deletions packages/core-js/internals/url-constructor-detection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
5 changes: 4 additions & 1 deletion packages/core-js/modules/web.url-search-params.delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */) {
Expand Down
4 changes: 3 additions & 1 deletion packages/core-js/modules/web.url-search-params.has.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
9 changes: 7 additions & 2 deletions tests/compat/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d9b3fdc

Please sign in to comment.