Skip to content

Validate RegExp named group IdentifierName grammar #617

@frostney

Description

@frostney

Summary

ParseGroupName in the regex compiler accepts any characters until > without validating that the name follows the ECMAScript IdentifierName grammar.

Why

Per ES2026 §22.2.1, the GroupName in (?<name>...) and \k<name> must be a valid IdentifierName: starting with IdentifierStart (letter, _, $, or \u escape), followed by IdentifierPart characters. Empty names, names starting with digits, and names containing hyphens should all be SyntaxErrors.

Current behavior

new RegExp('(?<1>a)') and new RegExp('(?<a-b>a)') are silently accepted.

Expected behavior

Both throw SyntaxError.

Scope notes

  • Source: Goccia.RegExp.Compiler.pas ParseGroupName
  • Not a regression from this PR — the old TRegExpr engine handled named groups via string preprocessing without grammar validation either
  • 4 test262 named-groups tests reference this: non-unicode-property-names-valid.js, non-unicode-property-names.js, unicode-property-names-valid.js, unicode-property-names.js

Metadata

Metadata

Assignees

No one assigned

    Labels

    engineTGocciaEngine: language semantics, ECMAScript built-ins, parser, interpreter, bytecode VMspec complianceMismatch against official JavaScript/TypeScript specification

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions