From 1a7ba6f6d46742113e98f77d91b275b6cc2ce6b3 Mon Sep 17 00:00:00 2001 From: Miccah Date: Thu, 12 Aug 2021 11:05:50 -0500 Subject: [PATCH] vweb: fix catchall route (#11168) --- vlib/vweb/route_test.v | 12 ++++++++++++ vlib/vweb/vweb.v | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/vlib/vweb/route_test.v b/vlib/vweb/route_test.v index 2025fa3ba..af745fb03 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 dc6f4f6a3..394d34695 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 } -- 2.30.2