From 19bd05801832079e14fa7d8e83277d9d3a250183 Mon Sep 17 00:00:00 2001 From: Denis Pushkarev Date: Tue, 5 Dec 2023 21:28:33 +0700 Subject: [PATCH] fix `RegExp` named capture groups object prototype --- CHANGELOG.md | 1 + packages/core-js/modules/es.regexp.constructor.js | 3 ++- tests/unit-global/es.regexp.constructor.js | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ccb4654a886..8f744fc8d37d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ - Relaxed some specific cases of [`Number.fromString`](https://github.com/tc39/proposal-number-fromstring) validation before clarification of [proposal-number-fromstring/24](https://github.com/tc39/proposal-number-fromstring/issues/24) - Fixed `@@toStringTag` property descriptors on DOM collections, [#1312](https://github.com/zloirock/core-js/issues/1312) - Fixed the order of arguments validation in `Array` iteration methods, [#1313](https://github.com/zloirock/core-js/issues/1313) +- Fixed `RegExp` named capture groups object prototype (should be `null`) - Some minor `atob` / `btoa` improvements - Compat data improvements: - [`Promise.withResolvers`](https://github.com/tc39/proposal-promise-with-resolvers) marked as shipped from FF121 diff --git a/packages/core-js/modules/es.regexp.constructor.js b/packages/core-js/modules/es.regexp.constructor.js index f922ed5b5555..a12a5a3e0291 100644 --- a/packages/core-js/modules/es.regexp.constructor.js +++ b/packages/core-js/modules/es.regexp.constructor.js @@ -5,6 +5,7 @@ var uncurryThis = require('../internals/function-uncurry-this'); var isForced = require('../internals/is-forced'); var inheritIfRequired = require('../internals/inherit-if-required'); var createNonEnumerableProperty = require('../internals/create-non-enumerable-property'); +var create = require('../internals/object-create'); var getOwnPropertyNames = require('../internals/object-get-own-property-names').f; var isPrototypeOf = require('../internals/object-is-prototype-of'); var isRegExp = require('../internals/is-regexp'); @@ -77,7 +78,7 @@ var handleNCG = function (string) { var index = 0; var result = ''; var named = []; - var names = {}; + var names = create(null); var brackets = false; var ncg = false; var groupid = 0; diff --git a/tests/unit-global/es.regexp.constructor.js b/tests/unit-global/es.regexp.constructor.js index f9ed5a13da22..9a376d1dafc7 100644 --- a/tests/unit-global/es.regexp.constructor.js +++ b/tests/unit-global/es.regexp.constructor.js @@ -3,6 +3,8 @@ import { DESCRIPTORS, GLOBAL } from '../helpers/constants.js'; import { nativeSubclass } from '../helpers/helpers.js'; +const { getPrototypeOf } = Object; + if (DESCRIPTORS) { QUnit.test('RegExp constructor', assert => { const Symbol = GLOBAL.Symbol || {}; @@ -80,6 +82,7 @@ if (DESCRIPTORS) { // eslint-disable-next-line regexp/no-unused-capturing-group -- required for testing assert.same(RegExp('(b)').exec('b').groups, undefined, 'NCG #2'); const { groups } = RegExp('foo:(?\\w+),bar:(?\\w+)').exec('foo:abc,bar:def'); + assert.same(getPrototypeOf(groups), null, 'null prototype'); assert.deepEqual(groups, { foo: 'abc', bar: 'def' }, 'NCG #3'); // fails in Safari // assert.same(Object.getPrototypeOf(groups), null, 'NCG #4');