Skip to content

Commit f053f99

Browse files
authored
net.http.file: use urllib decode uri, to handle urls to files that have unicode characters in their name (fix #23683) (#23684)
1 parent dacc738 commit f053f99

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

vlib/net/http/file/static_server.v

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import time
66
import runtime
77
import net.http
88
import net.http.mime
9+
import net.urllib
910

1011
@[params]
1112
pub struct StaticServeParams {
@@ -63,10 +64,17 @@ const no_such_file_doc = '<!DOCTYPE html><h1>no such file</h1>'
6364
fn (mut h StaticHttpHandler) handle(req http.Request) http.Response {
6465
mut res := http.new_response(body: '')
6566
sw := time.new_stopwatch()
67+
mut url := urllib.query_unescape(req.url) or {
68+
log.warn('bad request; url: ${req.url} ')
69+
res.set_status(.bad_request)
70+
res.body = '<!DOCTYPE html><h1>url decode fail</h1>'
71+
res.header.add(.content_type, 'text/html; charset=utf-8')
72+
return res
73+
}
6674
defer {
67-
log.info('took: ${sw.elapsed().microseconds():6}µs, status: ${res.status_code}, size: ${res.body.len:9}, url: ${req.url}')
75+
log.info('took: ${sw.elapsed().microseconds():6}µs, status: ${res.status_code}, size: ${res.body.len:9}, url: ${url}')
6876
}
69-
mut uri_path := req.url.all_after_first('/').trim_right('/')
77+
mut uri_path := url.all_after_first('/').trim_right('/')
7078
requested_file_path := os.norm_path(os.real_path(os.join_path_single(h.params.folder,
7179
uri_path)))
7280
if !requested_file_path.starts_with(h.params.folder) {

0 commit comments

Comments
 (0)