From 373aa3dbc8c4f54dc6c254895a0a687c3888cbb9 Mon Sep 17 00:00:00 2001 From: Louis Schmieder Date: Wed, 8 Jul 2020 22:15:37 +0200 Subject: [PATCH] vweb: router: fix trailing / (#5760) --- vlib/vweb/vweb.v | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/vlib/vweb/vweb.v b/vlib/vweb/vweb.v index 25fe494349..d3178b96a6 100644 --- a/vlib/vweb/vweb.v +++ b/vlib/vweb/vweb.v @@ -336,7 +336,7 @@ fn handle_conn(conn net.Socket, mut app T) { //t := time.ticks() //mut action := '' mut route_words := []string{} - mut url_words := vals[1][1..].split('/') + mut url_words := vals[1][1..].split('/').filter(it != '') if url_words.len == 0 { @@ -372,12 +372,18 @@ fn handle_conn(conn net.Socket, mut app T) { } } else { route_words = attrs[1..].split('/') - if url_words.len == route_words.len || (url_words.len >= route_words.len && route_words.last().ends_with('...')) { + if url_words.len == route_words.len || (url_words.len >= route_words.len - 1 && route_words.last().ends_with('...')) { // match `/:user/:repo/tree` to `/vlang/v/tree` mut matching := false mut unknown := false mut variables := []string{cap: route_words.len} for i in 0..route_words.len { + if url_words.len == i { + variables << '' + matching = true + unknown = true + break + } if url_words[i] == route_words[i] { // no parameter matching = true