Skip to content

Commit

Permalink
Merge pull request #155 from jprobinson/master
Browse files Browse the repository at this point in the history
[bugfix] Allow case insensitive regexp groups (fix regression in #144)
  • Loading branch information
elithrar committed Mar 7, 2016
2 parents 147a95f + 65c2651 commit acf3be1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 10 additions & 0 deletions mux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,16 @@ func TestPath(t *testing.T) {
path_template: `/{product-category:a|(b/c)}/{product-name}/{product-id:[0-9]+}`,
shouldMatch: true,
},
{
title: "Path route with multiple hyphenated names and patterns with pipe and case insensitive, match",
route: new(Route).Path("/{type:(?i:daily|mini|variety)}-{date:\\d{4,4}-\\d{2,2}-\\d{2,2}}"),
request: newRequest("GET", "http://localhost/daily-2016-01-01"),
vars: map[string]string{"type": "daily", "date": "2016-01-01"},
host: "",
path: "/daily-2016-01-01",
path_template: `/{type:(?i:daily|mini|variety)}-{date:\d{4,4}-\d{2,2}-\d{2,2}}`,
shouldMatch: true,
},
}

for _, test := range tests {
Expand Down
7 changes: 2 additions & 5 deletions regexp.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,8 @@ func newRouteRegexp(tpl string, matchHost, matchPrefix, matchQuery, strictSlash
tpl[idxs[i]:end])
}
// Build the regexp pattern.
if patt[0] == '(' && patt[len(patt)-1] == ')' {
fmt.Fprintf(pattern, "%s%s", regexp.QuoteMeta(raw), patt)
} else {
fmt.Fprintf(pattern, "%s(%s)", regexp.QuoteMeta(raw), patt)
}
fmt.Fprintf(pattern, "%s(?P<%s>%s)", regexp.QuoteMeta(raw), varGroupName(i/2), patt)

// Build the reverse template.
fmt.Fprintf(reverse, "%s%%s", raw)

Expand Down

0 comments on commit acf3be1

Please sign in to comment.