mirror of
https://github.com/labstack/echo.git
synced 2024-12-24 20:14:31 +02:00
Quote regex meta characters in Rewrite (#1541)
Currently there is a half and half situation where the user can't use regex (fully) because * will be replaced with (.*), yet they also can't just enter any old string, because meta chars like . would need escaping. e.g. currently *.html wouldn't work as intended, and instead *\.html should be used. Work around this by using regexp's QuoteMeta function to sanitise the input before handling it.
This commit is contained in:
parent
fc4b1c0a83
commit
542835808e
@ -57,7 +57,8 @@ func RewriteWithConfig(config RewriteConfig) echo.MiddlewareFunc {
|
|||||||
|
|
||||||
// Initialize
|
// Initialize
|
||||||
for k, v := range config.Rules {
|
for k, v := range config.Rules {
|
||||||
k = strings.Replace(k, "*", "(.*)", -1)
|
k = regexp.QuoteMeta(k)
|
||||||
|
k = strings.Replace(k, `\*`, "(.*)", -1)
|
||||||
k = k + "$"
|
k = k + "$"
|
||||||
config.rulesRegex[regexp.MustCompile(k)] = v
|
config.rulesRegex[regexp.MustCompile(k)] = v
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user