mirror of
https://github.com/metosin/reitit.git
synced 2025-12-17 16:31:11 +00:00
Fix resource handler path matching
File/resource handler checks that uri actually matches to path instead of comparing just path length to uri length.
This commit is contained in:
parent
d57851c2d3
commit
2ed5b48067
2 changed files with 7 additions and 5 deletions
|
|
@ -208,9 +208,9 @@
|
||||||
join-paths (fn [& paths]
|
join-paths (fn [& paths]
|
||||||
(str/replace (str/replace (str/join "/" paths) #"([/]+)" "/") #"/$" ""))
|
(str/replace (str/replace (str/join "/" paths) #"([/]+)" "/") #"/$" ""))
|
||||||
response (fn [path]
|
response (fn [path]
|
||||||
(if-let [response (or (paths (join-paths "/" path))
|
(if-let [response (or (paths (join-paths "/" path))
|
||||||
(response-fn path options))]
|
(response-fn path options))]
|
||||||
(response/content-type response (mime-type/ext-mime-type path))))
|
(response/content-type response (mime-type/ext-mime-type path))))
|
||||||
path-or-index-response (fn [path uri]
|
path-or-index-response (fn [path uri]
|
||||||
(or (response path)
|
(or (response path)
|
||||||
(loop [[file & files] index-files]
|
(loop [[file & files] index-files]
|
||||||
|
|
@ -221,8 +221,8 @@
|
||||||
handler (if path
|
handler (if path
|
||||||
(fn [request]
|
(fn [request]
|
||||||
(let [uri (:uri request)]
|
(let [uri (:uri request)]
|
||||||
(if-let [path (if (>= (count uri) path-size) (subs uri path-size))]
|
(if (.startsWith uri path)
|
||||||
(path-or-index-response path uri))))
|
(path-or-index-response (subs uri path-size) uri))))
|
||||||
(fn [request]
|
(fn [request]
|
||||||
(let [uri (:uri request)
|
(let [uri (:uri request)
|
||||||
path (-> request :path-params parameter)]
|
path (-> request :path-params parameter)]
|
||||||
|
|
|
||||||
|
|
@ -491,6 +491,8 @@
|
||||||
|
|
||||||
(testing "not found"
|
(testing "not found"
|
||||||
(let [response (app (request "/not-found"))]
|
(let [response (app (request "/not-found"))]
|
||||||
|
(is (= 404 (:status response))))
|
||||||
|
(let [response (app {:uri "/XXXXX/hello.json" :request-method :get})]
|
||||||
(is (= 404 (:status response)))))
|
(is (= 404 (:status response)))))
|
||||||
|
|
||||||
(testing "3-arity"
|
(testing "3-arity"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue