Skip to content

Commit 9bd5b95

Browse files
ldezjuliens
authored andcommitted
Revert "[bugfix] fail fast if regex is incorrectly specified using capturing groups. (gorilla#218)"
This reverts commit 392c28f.
1 parent 91708ff commit 9bd5b95

File tree

3 files changed

+0
-22
lines changed

3 files changed

+0
-22
lines changed

doc.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,6 @@ 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-
6560
And this is all you need to know about the basic usage. More advanced options
6661
are explained below.
6762

mux_test.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,16 +1757,6 @@ func TestSubrouterErrorHandling(t *testing.T) {
17571757
}
17581758
}
17591759

1760-
// See: https://github.com/gorilla/mux/issues/200
1761-
func TestPanicOnCapturingGroups(t *testing.T) {
1762-
defer func() {
1763-
if recover() == nil {
1764-
t.Errorf("(Test that capturing groups now fail fast) Expected panic, however test completed successfully.\n")
1765-
}
1766-
}()
1767-
NewRouter().NewRoute().Path("/{type:(promo|special)}/{promoId}.json")
1768-
}
1769-
17701760
// ----------------------------------------------------------------------------
17711761
// Helpers
17721762
// ----------------------------------------------------------------------------

regexp.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,6 @@ func newRouteRegexp(tpl string, typ regexpType, options routeRegexpOptions) (*ro
129129
if errCompile != nil {
130130
return nil, errCompile
131131
}
132-
133-
// Check for capturing groups which used to work in older versions
134-
if reg.NumSubexp() != len(idxs)/2 {
135-
panic(fmt.Sprintf("route %s contains capture groups in its regexp. ", template) +
136-
"Only non-capturing groups are accepted: e.g. (?:pattern) instead of (pattern)")
137-
}
138-
139132
// Done!
140133
return &routeRegexp{
141134
template: template,

0 commit comments

Comments
 (0)