mirror of
https://github.com/caddyserver/caddy.git
synced 2026-11-21 15:29:45 +00:00
caddyhttp: document CEL raw strings for regexp patterns (#8280)
Co-authored-by: hikmetba-bit <hikmetba-bit@users.noreply.github.com>
This commit is contained in:
parent
754078da65
commit
4fce7c8bbc
1 changed files with 16 additions and 0 deletions
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue