Skip to content

Commit bd6899d

Browse files
committed
Added documentation, changed error message.
1 parent 6f4a83b commit bd6899d

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

doc.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ calling mux.Vars():
5757
vars := mux.Vars(request)
5858
category := vars["category"]
5959
60+
Note that if any capturing groups are present, mux will panic() during parsing. To prevent
61+
this, convert any capturing groups to non-capturing, e.g. change "/{sort:(asc|desc)}" to
62+
"/{sort:(?:asc|desc)}". This is a change from prior versions which behaved unpredictably
63+
when capturing groups were present.
64+
6065
And this is all you need to know about the basic usage. More advanced options
6166
are explained below.
6267

regexp.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ func newRouteRegexp(tpl string, matchHost, matchPrefix, matchQuery, strictSlash,
112112

113113
// Check for capturing groups which used to work in older versions
114114
if reg.NumSubexp() != len(idxs)/2 {
115-
panic("Regexp appears to be using capturing groups. To fix, see: https://github.com/gorilla/mux/issues/200")
115+
panic(fmt.Sprintf("route %s contains capture groups in its regexp. ", template) +
116+
"Only non-capturing groups are accepted: e.g. (?:pattern) instead of (pattern)")
116117
}
117118

118119
// Done!

0 commit comments

Comments
 (0)