Skip to content

Commit

Permalink
fix: route path regex check error
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Jul 30, 2019
1 parent 5299637 commit fe60d10
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions route.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,17 @@ func (r *Route) goodInfo() {
}

// check custom var regex string.
// ERROR: "{id:(\d+)}" -> "(\d+)"
// RIGHT: "{id:\d+}"
// ERROR:
// "{id:(\d+)}" -> "(\d+)"
//
// RIGHT:
// "{id:\d+}"
// "{id:(?:\d+)}"
func (r *Route) goodRegexString(n, v string) {
if strings.IndexByte(v, '(') != -1 {
panicf("invalid path var regex string, dont allow add char '('. var: %s, regex: %s", n, v)
}
pos := strings.IndexByte(v, '(')

if strings.IndexByte(v, ')') != -1 {
panicf("invalid path var regex string, dont allow add char ')'. var: %s, regex: %s", n, v)
if pos != -1 && pos < len(v) && v[pos+1] != '?' {
panicf("invalid path var regex string, dont allow add char '('. var: %s, regex: %s", n, v)
}
}

Expand Down

0 comments on commit fe60d10

Please sign in to comment.