Handle URL-encoded paths in file and resource handlers

This commit is contained in:
Miikka Koskinen 2021-04-30 14:28:12 +03:00
parent f212edfcd6
commit 1297cfd902
3 changed files with 26 additions and 5 deletions

View file

@ -0,0 +1 @@
hello

View file

@ -222,12 +222,12 @@
(recur files))))))
handler (if path
(fn [request]
(let [uri (:uri request)]
(let [uri (impl/url-decode (:uri request))]
(if (str/starts-with? uri path)
(or (path-or-index-response (subs uri path-size) uri)
(not-found-handler request)))))
(fn [request]
(let [uri (:uri request)
(let [uri (impl/url-decode (:uri request))
path (-> request :path-params parameter)]
(or (path-or-index-response path uri)
(not-found-handler request)))))]

View file

@ -484,6 +484,11 @@
(is (get-in response [:headers "Last-Modified"]))
(is (= "<xml><hello>file</hello></xml>\n" (slurp (:body response))))))
(testing "with url decoding"
(let [response (app (request "/with%20space.txt"))]
(is (= 200 (:status response)))
(is (= "hello\n" (slurp (:body response))))))
(testing "index-files"
(let [response (app (request "/docs"))]
(is (= (redirect "/docs/index.html") response)))
@ -520,6 +525,11 @@
(is (get-in response [:headers "Last-Modified"]))
(is (= "<xml><hello>file</hello></xml>\n" (slurp (:body response))))))
(testing "with url decoding"
(let [response (app (request "/with%20space.txt"))]
(is (= 200 (:status response)))
(is (= "hello\n" (slurp (:body response))))))
(testing "index-files"
(let [response (app (request "/docs"))]
(is (= (redirect "/docs/index.html") response)))
@ -557,6 +567,11 @@
(is (get-in response [:headers "Last-Modified"]))
(is (= "<xml><hello>file</hello></xml>\n" (slurp (:body response))))))
(testing "with url decoding"
(let [response (app (request "/with%20space.txt"))]
(is (= 200 (:status response)))
(is (= "hello\n" (slurp (:body response))))))
(testing "index-files"
(let [response (app (request "/docs"))]
(is (= (redirect "/docs/index.html") response)))
@ -595,6 +610,11 @@
(is (get-in response [:headers "Last-Modified"]))
(is (= "<xml><hello>file</hello></xml>\n" (slurp (:body response))))))
(testing "with url decoding"
(let [response (app (request "/with%20space.txt"))]
(is (= 200 (:status response)))
(is (= "hello\n" (slurp (:body response))))))
(testing "index-files"
(let [response (app (request "/docs"))]
(is (= (redirect "/docs/index.html") response)))