VividCortex / siesta

Composable framework for writing HTTP handlers in Go.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bad regular expression built by Route()

gkristic opened this issue · comments

The regular expression built up by Route() upon variables in the path is not syntactically correct. I'm going to fix the construction now, but I think I'll open another issue to make Route() more robust. I think we should use Compile() instead of MustCompile(). The later is primarily meant for static expressions that you may introduce during initialization, so that you may say things such as:

var number = regexp.MustCompile("^[1-9]\\d*$")

without having to deal with error results. But other than that Compile() is a better fit, especially when the expression itself is dynamically built from user input, like in this case. We don't know whether the pattern that's part of the expression used here is clean/safe to use in a regular expression. Using MustCompile() results in a panic in case of bad input. That's quite an unwelcome output for this.