vweb: fix catchall route (#11168)
parent
a8905e2788
commit
1a7ba6f6d4
|
@ -268,3 +268,15 @@ fn test_route_params_array() {
|
||||||
route: '/:a/:b/:c...'
|
route: '/:a/:b/:c...'
|
||||||
}.test_param(['one', 'two', 'three/d/e'])
|
}.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'])
|
||||||
|
}
|
||||||
|
|
|
@ -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 {
|
fn route_matches(url_words []string, route_words []string) ?[]string {
|
||||||
// URL path should be at least as long as the route path
|
// 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 {
|
if url_words.len < route_words.len {
|
||||||
return none
|
return none
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue