From 4fce7c8bbcf260f1dfdc10f9f7d4d1ca76885a24 Mon Sep 17 00:00:00 2001 From: Francis Lavoie Date: Thu, 29 Oct 2026 09:08:28 -0400 Subject: [PATCH] caddyhttp: document CEL raw strings for regexp patterns (#8280) Co-authored-by: hikmetba-bit --- modules/caddyhttp/matchers.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/modules/caddyhttp/matchers.go b/modules/caddyhttp/matchers.go index ce4f0bd61..a65e4887a 100644 --- a/modules/caddyhttp/matchers.go +++ b/modules/caddyhttp/matchers.go @@ -843,6 +843,13 @@ func (m MatchPathRE) MatchWithError(r *http.Request) (bool, error) { // Example: // // expression path_regexp('^/bar') +// +// The pattern is a CEL string literal, so CEL's own escape sequences +// (e.g. \b, \n, \t) are interpreted before the result reaches the regexp +// engine. A pattern that needs a literal backslash escape meant for the +// regexp engine, such as \b for a word boundary, should be written as a +// CEL raw string (prefixed with r) so CEL passes the backslash through +// unchanged: expression path_regexp(r'^/bar\b'). func (MatchPathRE) CELLibrary(ctx caddy.Context) (cel.Library, error) { unnamedPattern, err := CELMatcherImpl( "path_regexp", @@ -1309,6 +1316,15 @@ func (m MatchHeaderRE) Validate() error { // Example: // // expression header_regexp('foo', 'Field', 'fo+') +// +// The pattern is a CEL string literal, so CEL's own escape sequences +// (e.g. \b, \n, \t) are interpreted before the result reaches the regexp +// engine. A pattern that needs a literal backslash escape meant for the +// regexp engine, such as \b for a word boundary, should be written as a +// CEL raw string (prefixed with r) so CEL passes the backslash through +// unchanged: expression header_regexp('foo', 'User-Agent', r'bot\b'). +// Without the r prefix, \b is interpreted by CEL as a backspace +// character before the regexp engine ever sees the pattern. func (MatchHeaderRE) CELLibrary(ctx caddy.Context) (cel.Library, error) { unnamedPattern, err := CELMatcherImpl( "header_regexp",