Skip to content

Commit

Permalink
properly replace capture groups in URLWith / URLFor
Browse files Browse the repository at this point in the history
if specifying a standard capture group (as specified by
http://golang.org/pkg/regexp/syntax/) in a route, the replacement
in URLWith needs to include the appropriate regex, in addition
to the :name sugar
  • Loading branch information
thevisus committed Jun 16, 2014
1 parent 7fbb8b2 commit a82e3f4
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion router.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (r *route) Handle(c Context, res http.ResponseWriter) {
// URLWith returns the url pattern replacing the parameters for its values
func (r *route) URLWith(args []string) string {
if len(args) > 0 {
reg := regexp.MustCompile(`:[^/#?()\.\\]+`)
reg := regexp.MustCompile(`:[^/#?()\.\\]+|\(\?P<[a-zA-Z0-9]+>.*\)`)
argCount := len(args)
i := 0
url := reg.ReplaceAllStringFunc(r.pattern, func(m string) string {
Expand Down

0 comments on commit a82e3f4

Please sign in to comment.