Merge pull request #489 from metosin/fix-resource-handler-url-decoding

Handle URL-encoded paths in file and resource handlers
This commit is contained in:
Tommi Reiman 2021-08-03 13:34:06 +03:00 committed by GitHub
commit 2747428dea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 5 deletions

View file

@ -27,6 +27,10 @@ We use [Break Versioning][breakver]. The version numbers follow a `<major>.<mino
[io.pedestal/pedestal.service "0.5.9"] is available but we use "0.5.8" [io.pedestal/pedestal.service "0.5.9"] is available but we use "0.5.8"
``` ```
### `reitit-ring`
* Fixes `reitit.ring/create-resource-handler` and `reitit.ring/create-file-handler` to support URL-escaped characters. [#484](https://github.com/metosin/reitit/issues/484). PR [#489](https://github.com/metosin/reitit/pull/489).
### `reitit-malli` ### `reitit-malli`
* FIX: Malli response coercision seems to do nothing at all [#498](https://github.com/metosin/reitit/pull/501) * FIX: Malli response coercision seems to do nothing at all [#498](https://github.com/metosin/reitit/pull/501)

View file

@ -0,0 +1 @@
hello

View file

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

View file

@ -484,6 +484,11 @@
(is (get-in response [:headers "Last-Modified"])) (is (get-in response [:headers "Last-Modified"]))
(is (= "<xml><hello>file</hello></xml>\n" (slurp (:body response)))))) (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" (testing "index-files"
(let [response (app (request "/docs"))] (let [response (app (request "/docs"))]
(is (= (redirect "/docs/index.html") response))) (is (= (redirect "/docs/index.html") response)))
@ -520,6 +525,11 @@
(is (get-in response [:headers "Last-Modified"])) (is (get-in response [:headers "Last-Modified"]))
(is (= "<xml><hello>file</hello></xml>\n" (slurp (:body response)))))) (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" (testing "index-files"
(let [response (app (request "/docs"))] (let [response (app (request "/docs"))]
(is (= (redirect "/docs/index.html") response))) (is (= (redirect "/docs/index.html") response)))
@ -557,6 +567,11 @@
(is (get-in response [:headers "Last-Modified"])) (is (get-in response [:headers "Last-Modified"]))
(is (= "<xml><hello>file</hello></xml>\n" (slurp (:body response)))))) (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" (testing "index-files"
(let [response (app (request "/docs"))] (let [response (app (request "/docs"))]
(is (= (redirect "/docs/index.html") response))) (is (= (redirect "/docs/index.html") response)))
@ -595,6 +610,11 @@
(is (get-in response [:headers "Last-Modified"])) (is (get-in response [:headers "Last-Modified"]))
(is (= "<xml><hello>file</hello></xml>\n" (slurp (:body response)))))) (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" (testing "index-files"
(let [response (app (request "/docs"))] (let [response (app (request "/docs"))]
(is (= (redirect "/docs/index.html") response))) (is (= (redirect "/docs/index.html") response)))