From 8b50a5a1713bab86d6ac068ef2e425f03b0ba674 Mon Sep 17 00:00:00 2001 From: Miccah Date: Wed, 5 May 2021 06:20:40 -0500 Subject: [PATCH] vweb: fix route matching on `/` (#10001) --- vlib/vweb/route_test.v | 4 ++++ vlib/vweb/vweb.v | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/vlib/vweb/route_test.v b/vlib/vweb/route_test.v index 7ca375cf7c..2025fa3baa 100644 --- a/vlib/vweb/route_test.v +++ b/vlib/vweb/route_test.v @@ -55,6 +55,10 @@ fn test_route_no_match() { url: '/a/b/c/d' route: '/a/b/c' }, + RoutePair{ + url: '/a/b/c' + route: '/' + }, ] for test in tests { test.test_no_match() diff --git a/vlib/vweb/vweb.v b/vlib/vweb/vweb.v index 57bea00d36..2a2242a84d 100644 --- a/vlib/vweb/vweb.v +++ b/vlib/vweb/vweb.v @@ -443,7 +443,7 @@ fn route_matches(url_words []string, route_words []string) ?[]string { } // The last route can end with ... indicating an array - if !route_words[route_words.len - 1].ends_with('...') { + if route_words.len == 0 || !route_words[route_words.len - 1].ends_with('...') { return none }