Skip to content

fix: allow regex metacharacters in arguments#76

Open
tomholford wants to merge 1 commit intocaddyserver:masterfrom
tomholford:fix/regex-argument-metachars
Open

fix: allow regex metacharacters in arguments#76
tomholford wants to merge 1 commit intocaddyserver:masterfrom
tomholford:fix/regex-argument-metachars

Conversation

@tomholford
Copy link
Copy Markdown

@tomholford tomholford commented Apr 15, 2026

Summary

The argument token's regex only allowed [a-zA-Z\-_+.\\\/*:$0-9@], so path_regexp-style matchers containing (, ), [, ], |, ?, or ^ produced an ERROR node that swallowed everything after the first metacharacter — breaking both parsing and downstream syntax highlighting for the rest of the file.

Repro:

example.com {
    @broken path_regexp /foo/(bar|baz).*
    @also-broken path_regexp /foo/[0-9]+

    handle /xyz {
        file_server
    }
}

Before this change the whole file after @broken falls into an ERROR node.

Fix

Widen the unquoted-argument character classes to include ()[]|?^ so regex arguments lex as a single argument token and the rest of the file parses cleanly. = was intentionally left out to preserve status_code_fallback (=404) precedence.

Test plan

  • New path_regexp with Regex corpus case in test/corpus/named_matchers.txt
  • tree-sitter test — 43/43 passing (was 42 before)
  • Existing Status Code Fallback test still passes
  • All examples/*.caddyfile still parse without new errors

Context

Originally surfaced via a downstream Zed extension bug report: nusnewob/caddyfile-zed#7

The `argument` token's regex only allowed `[a-zA-Z\-_+.\\\/*:$0-9@]`, so
`path_regexp`-style matchers containing `(`, `)`, `[`, `]`, `|`, `?`, or
`^` produced an ERROR node that swallowed everything after the first
metacharacter.

Example from a real Caddyfile:

    @broken path_regexp /foo/(bar|baz).*
    @also-broken path_regexp /foo/[0-9]+

Widen the unquoted-argument char classes to include `()[]|?^` so regex
arguments lex as a single token and parse cleanly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant