1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

vweb: router: fix trailing / (#5760)

This commit is contained in:
Louis Schmieder 2020-07-08 22:15:37 +02:00 committed by GitHub
parent e3581c5cf6
commit 373aa3dbc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -336,7 +336,7 @@ fn handle_conn<T>(conn net.Socket, mut app T) {
//t := time.ticks() //t := time.ticks()
//mut action := '' //mut action := ''
mut route_words := []string{} 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 { if url_words.len == 0 {
@ -372,12 +372,18 @@ fn handle_conn<T>(conn net.Socket, mut app T) {
} }
} else { } else {
route_words = attrs[1..].split('/') 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` // match `/:user/:repo/tree` to `/vlang/v/tree`
mut matching := false mut matching := false
mut unknown := false mut unknown := false
mut variables := []string{cap: route_words.len} mut variables := []string{cap: route_words.len}
for i in 0..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] { if url_words[i] == route_words[i] {
// no parameter // no parameter
matching = true matching = true