Skip to content

Commit

Permalink
Disallow empty capture groups
Browse files Browse the repository at this point in the history
  • Loading branch information
hlysine committed Aug 19, 2023
1 parent 03288d5 commit 97a820b
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/modifiers/CaptureModifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default class CaptureModifier implements RegExpModifier {
}

public modify(regExp: string): [string, string?] {
if (regExp.length === 0) throw new Error('Empty capture group');
if (isBracketGroup(regExp) && regExp.startsWith('(?:')) {
if (this.name === undefined) return ['(' + regExp.substring(3)];
return [`(?<${this.name}>` + regExp.substring(3)];
Expand Down

0 comments on commit 97a820b

Please sign in to comment.