Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing case insensitive regexp groups after PR #144 #155

Merged
merged 1 commit into from
Mar 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fixing regexp changes from PR #144
  • Loading branch information
jprobinson committed Mar 7, 2016
commit 65c2651643a9eb5438d10f1c492ba892fe96244f
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