diff --git a/vlib/vweb/route_test.v b/vlib/vweb/route_test.v index 2025fa3baa..af745fb03e 100644 --- a/vlib/vweb/route_test.v +++ b/vlib/vweb/route_test.v @@ -268,3 +268,15 @@ fn test_route_params_array() { route: '/:a/:b/:c...' }.test_param(['one', 'two', 'three/d/e']) } + +fn test_route_index_path() { + RoutePair{ + url: '/' + route: '/:path...' + }.test_param(['/']) + + RoutePair{ + url: '/foo/bar' + route: '/:path...' + }.test_param(['/foo/bar']) +} diff --git a/vlib/vweb/vweb.v b/vlib/vweb/vweb.v index dc6f4f6a39..394d346959 100644 --- a/vlib/vweb/vweb.v +++ b/vlib/vweb/vweb.v @@ -441,6 +441,10 @@ fn handle_conn(mut conn net.TcpConn, mut app T) { fn route_matches(url_words []string, route_words []string) ?[]string { // URL path should be at least as long as the route path + // except for the catchall route (`/:path...`) + if route_words.len == 1 && route_words[0].starts_with(':') && route_words[0].ends_with('...') { + return ['/' + url_words.join('/')] + } if url_words.len < route_words.len { return none }