Skip to content

Fix 'Invalid regular expression: invalid group specifier name' error in regex validation #242

Description

@jingfang

Bug Description

The application throws an "Invalid regular expression: invalid group specifier name" error when processing certain regex patterns. This error occurs in JavaScript/TypeScript when using named capture groups or other regex features that may not be properly escaped or supported.

Affected Files

  1. src/lib/hooksManager.ts:133 - Where user-provided regex patterns are validated in the hooks configuration
  2. src/components/FloatingPromptInput.tsx:697-703 - Where file paths are escaped and used in RegExp constructors

Root Cause

The error typically occurs when:

  • A regex pattern contains named capture groups using the syntax (?<name>...)
  • Special characters in file paths are not properly escaped before being used in RegExp constructors
  • The regex pattern contains syntax that's not valid in JavaScript's RegExp implementation

Proposed Solution

  1. Add proper error handling around RegExp constructor calls
  2. Validate regex patterns before attempting to create RegExp objects
  3. Improve escaping of special characters in file paths
  4. Provide clear error messages to users when invalid regex patterns are encountered

Steps to Reproduce

  1. Configure a hook with a regex pattern containing named capture groups
  2. Or use a file path with special regex characters in the FloatingPromptInput component
  3. The error will be thrown when the RegExp constructor tries to parse the invalid pattern

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions