1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-18 02:17:05 +00:00

add iris.TrimParamFilePart

read more at: #2024
This commit is contained in:
Gerasimos (Makis) Maropoulos
2022-12-24 05:04:16 +02:00
parent 85fd5ead04
commit 29c8f44c93
6 changed files with 144 additions and 3 deletions

View File

@@ -27,10 +27,26 @@ func Parse(fullpath string, paramTypes []ast.ParamType) ([]*ast.ParamStatement,
}
// if it's not a named path parameter of the new syntax then continue to the next
if s[0] != lexer.Begin || s[len(s)-1] != lexer.End {
// if s[0] != lexer.Begin || s[len(s)-1] != lexer.End {
// continue
// }
// Modified to show an error on a certain invalid action.
if s[0] != lexer.Begin {
continue
}
if s[len(s)-1] != lexer.End {
if idx := strings.LastIndexByte(s, lexer.End); idx > 2 && idx < len(s)-1 /* at least {x}*/ {
// Do NOT allow something more than a dynamic path parameter in the same path segment,
// e.g. /{param}-other-static-part/. See #2024.
// this allows it but NO (see trie insert): s = s[0 : idx+1]
return nil, fmt.Errorf("%s: invalid path part: dynamic path parameter and other parameters or static parts are not allowed in the same exact request path part, use the {regexp} function alone instead", s)
} else {
continue
}
}
p.Reset(s)
stmt, err := p.Parse(paramTypes)
if err != nil {