vweb: fix catchall route (#11168)

pull/11155/head^2
Miccah 2021-08-12 11:05:50 -05:00 committed by GitHub
parent a8905e2788
commit 1a7ba6f6d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

@ -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'])
}

View File

@ -441,6 +441,10 @@ fn handle_conn<T>(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
}