Skip to content

EventBus.matchesPattern() regex metacharacters not escaped #69

@thedhanawada

Description

@thedhanawada

Problem

The EventBus.matchesPattern() method in src/core/EventBus.js:171-173 only escapes the * wildcard character but does not escape other regex metacharacters. This causes unintended pattern matches.

Affected Code

// EventBus.js:171-173
matchesPattern(eventName, pattern) {
  const regex = new RegExp('^' + pattern.replace(/\*/g, '.*') + '$');
  return regex.test(eventName);
}

Issue

A pattern like event.add would incorrectly match event_add, eventXadd, etc. because the . character is treated as a regex wildcard (matching any character) rather than a literal dot.

Metacharacters that should be escaped: ., +, ?, (, ), [, ], {, }, |, ^, $, \

Expected Behavior

Only the * character should act as a wildcard. All other special regex characters should be treated as literals.

Solution

Escape all regex metacharacters except * before building the RegExp, or use a regex escape utility.

Metadata

Metadata

Assignees

No one assigned

    Labels

    phase:0-foundationImmediate fixes and test infrastructurepriority:highImportant for next milestonetype:bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions