Skip to content

Commit

Permalink
x.vweb: fix handling of static URL paths like /sub.folder/a_folder (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
davlgd committed Feb 18, 2024
1 parent 38cf923 commit 2568d33
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions vlib/x/vweb/tests/static_handler_test.v
Expand Up @@ -96,9 +96,13 @@ fn test_scans_subdirs() {

fn test_index_subdirs() {
x := http.get('${localserver}/sub_folder/')!
y := http.get('${localserver}/sub.folder/sub_folder')!

assert x.status() == .ok
assert x.body.trim_space() == 'OK'

assert y.status() == .ok
assert y.body.trim_space() == 'OK'
}

fn test_custom_mime_types() {
Expand Down
1 change: 1 addition & 0 deletions vlib/x/vweb/tests/testdata/sub.folder/sub_folder/index.htm
@@ -0,0 +1 @@
OK
1 change: 1 addition & 0 deletions vlib/x/vweb/tests/testdata/sub.folder/sub_folder/sub.txt
@@ -0,0 +1 @@
sub
4 changes: 3 additions & 1 deletion vlib/x/vweb/vweb.v
Expand Up @@ -934,7 +934,9 @@ fn route_matches(url_words []string, route_words []string) ?[]string {
fn serve_if_static[A, X](app &A, mut user_context X, url urllib.URL, host string) bool {
// TODO: handle url parameters properly - for now, ignore them
mut asked_path := url.path
if !asked_path.contains('.') && !asked_path.ends_with('/') {
base_path := os.base(asked_path)

if !base_path.contains('.') && !asked_path.ends_with('/') {
asked_path += '/'
}

Expand Down

0 comments on commit 2568d33

Please sign in to comment.