mirror of
https://github.com/metosin/reitit.git
synced 2025-12-16 16:01:11 +00:00
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:
commit
2747428dea
4 changed files with 30 additions and 5 deletions
|
|
@ -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"
|
||||
```
|
||||
|
||||
### `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`
|
||||
|
||||
* FIX: Malli response coercision seems to do nothing at all [#498](https://github.com/metosin/reitit/pull/501)
|
||||
|
|
|
|||
1
dev-resources/public/with space.txt
Normal file
1
dev-resources/public/with space.txt
Normal file
|
|
@ -0,0 +1 @@
|
|||
hello
|
||||
|
|
@ -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)))))]
|
||||
|
|
|
|||
|
|
@ -471,9 +471,9 @@
|
|||
|
||||
(testing "from root"
|
||||
(let [app (ring/ring-handler
|
||||
(ring/router
|
||||
["/*" (create nil)])
|
||||
(ring/create-default-handler))]
|
||||
(ring/router
|
||||
["/*" (create nil)])
|
||||
(ring/create-default-handler))]
|
||||
(testing "different file-types"
|
||||
(let [response (app (request "/hello.json"))]
|
||||
(is (= "application/json" (get-in response [:headers "Content-Type"])))
|
||||
|
|
@ -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)))
|
||||
|
|
|
|||
Loading…
Reference in a new issue