File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed
Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -151,6 +151,12 @@ open class HttpRouter {
151151 }
152152
153153 if let startStarNode = node. nodes [ " ** " ] {
154+ if startStarNode. isEndOfRoute {
155+ // ** at the end of a route works as a catch-all
156+ matchedNodes. append ( startStarNode)
157+ return
158+ }
159+
154160 let startStarNodeKeys = startStarNode. nodes. keys
155161 currentIndex += 1
156162 while currentIndex < count, let pathToken = pattern [ currentIndex] . removingPercentEncoding {
Original file line number Diff line number Diff line change @@ -85,6 +85,18 @@ class SwifterTestsHttpRouter: XCTestCase {
8585 XCTAssertNil ( router. route ( nil , path: " /a/e/f/g " ) )
8686 }
8787
88+ func testHttpRouterMultiplePathSegmentWildcardTail( ) {
89+
90+ router. register ( nil , path: " /a/b/** " , handler: { _ in
91+ return . ok( . htmlBody( " OK " ) )
92+ } )
93+
94+ XCTAssertNil ( router. route ( nil , path: " / " ) )
95+ XCTAssertNil ( router. route ( nil , path: " /a " ) )
96+ XCTAssertNotNil ( router. route ( nil , path: " /a/b/c/d/e/f/g " ) )
97+ XCTAssertNil ( router. route ( nil , path: " /a/e/f/g " ) )
98+ }
99+
88100 func testHttpRouterEmptyTail( ) {
89101
90102 router. register ( nil , path: " /a/b/ " , handler: { _ in
You can’t perform that action at this time.
0 commit comments