Skip to content

Commit

Permalink
fix RegExp named capture groups object prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Dec 5, 2023
1 parent 572d8d4 commit 19bd058
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion packages/core-js/modules/es.regexp.constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions tests/unit-global/es.regexp.constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || {};
Expand Down Expand Up @@ -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:(?<foo>\\w+),bar:(?<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');
Expand Down

0 comments on commit 19bd058

Please sign in to comment.