internal/rulematch
import "github.com/gofiber/fiber/v3/internal/rulematch"
Package rulematch provides pattern compilation and capture substitution shared by redirect and rewrite rules. Callers choose the pattern syntax and own destination normalization.
Functions
func CaptureTokens(pattern *regexp.Regexp, input string, unescaped bool) *strings.Replacer
Source: internal/rulematch/capture.go:24
CaptureTokens matches input and returns a replacer for its numbered capture groups ($1, $2, ...), or nil when the pattern does not match. A match without capture groups returns a non-nil replacer that leaves the target unchanged. Captures are preserved verbatim unless unescaped is set. In that case, path segments are escaped before substitution because rewrite decodes the resulting path again. This prevents a literal "%2e%2e" capture from becoming "..". Empty values and trailing slashes are preserved in either mode.
Adapted from https://github.com/labstack/echo/blob/master/middleware/rewrite.go.
func DotSegments(s string) int
Source: internal/rulematch/capture.go:44
DotSegments counts the "." and ".." segments of s as some reader may: "%2e" is a dot, "\", "%2f" and "%5c" are slashes, and "?" and "#" end a segment, not the count, so a capture cannot hide one.
func MustCompilePath(from string) *regexp.Regexp
Source: internal/rulematch/pattern.go:16
MustCompilePath compiles a rewrite pattern: path text matched as written, each "*" a "(.*)" capture.
func MustCompileRegexp(from string) *regexp.Regexp
Source: internal/rulematch/pattern.go:10
MustCompileRegexp compiles a redirect pattern: regexp syntax with its groups and flags, each "*" a "(.*)" capture. An invalid pattern panics.