Skip to content

Commit 4bd7d2a

Browse files
committed
Fix recursion by number with group subtypes
1 parent 63d1f41 commit 4bd7d2a

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

spec/recursion-spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ describe('recursion', () => {
108108
it('should match direct recursion', () => {
109109
expect('aabb').toMatch(regex({plugins: [recursion]})`^(?<r>a\g<1&R=2>?b)$`);
110110
expect('aab').not.toMatch(regex({plugins: [recursion]})`^(?<r>a\g<1&R=2>?b)$`);
111+
expect(() => regex({plugins: [recursion]})`^(a\g<1&R=2>?b)$`).toThrow();
111112
expect('aabb').toMatch(regex({plugins: [recursion], disable: {n: true}})`^(a\g<1&R=2>?b)$`);
112113
expect('aab').not.toMatch(regex({plugins: [recursion], disable: {n: true}})`^(a\g<1&R=2>?b)$`);
113114
});

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {Context, forEachUnescaped, getGroupContents, hasUnescaped, replaceUnesca
33
const gRToken = String.raw`\\g<(?<gRNameOrNum>[^>&]+)&R=(?<gRDepth>[^>]+)>`;
44
const recursiveToken = String.raw`\(\?R=(?<rDepth>[^\)]+)\)|${gRToken}`;
55
const namedCapturingDelim = String.raw`\(\?<(?![=!])(?<captureName>[^>]+)>`;
6-
const token = new RegExp(String.raw`${namedCapturingDelim}|${recursiveToken}|\\?.`, 'gsu');
6+
const token = new RegExp(String.raw`${namedCapturingDelim}|${recursiveToken}|\(\?|\\?.`, 'gsu');
77
const overlappingRecursionMsg = 'Cannot use multiple overlapping recursions';
88

99
/**

0 commit comments

Comments
 (0)