Skip to content

Custom patterns UI has no built-in test / preview against sample input #16

@NK2552003

Description

@NK2552003

The Manage Custom Patterns command lets users define regex patterns with a severity and category, but there is no way to test a new pattern against sample input before saving it. Developers will write patterns that either never match or match everything, and only discover this at paste time.

Problem

Writing a correct regex is non-trivial, especially for:

  • Patterns with lookaheads / lookbehinds
  • Patterns that need to avoid matching substrings of larger tokens
  • Patterns with catastrophic backtracking potential (e.g. (a+)+ style constructs)
    Currently a user writes a regex, saves it, pastes some test content, sees nothing happen (or sees everything flagged), and has no idea whether their pattern is wrong or their test input is wrong. The only debugging path is editing settings.json directly.

Proposed solution

Add a "Test pattern" panel to the custom patterns UI.

Scope:

  • A text input field labelled "Test input" in the add/edit pattern form
  • Live match/no-match indicator as the user types (debounced, ~200ms)
  • Highlight the matched substring within the test input
  • Warn if:
    • The pattern matches an empty string
    • The pattern has no anchors and could match anything (e.g. .*)
    • Basic catastrophic backtracking patterns are detected (e.g. nested quantifiers on the same character class)
  • The test field is local to the UI session — it is not saved
    Example UI state:
Pattern regex:  MYCOMPANY_[a-zA-Z0-9]{32}
Test input:     MYCOMPANY_aBcDeFgHiJkLmNoPqRsTuVwXyZ12
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                Match found  ✓

Acceptance criteria

  • "Test input" field appears in the add/edit pattern form
  • Match result updates live as the user types (debounced)
  • Matched substring is highlighted within the test input
  • Warning shown if the pattern matches an empty string
  • Warning shown for basic catastrophic backtracking patterns
  • Test input is not persisted anywhere

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions