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:
Kimmo Rantala 2020-10-15 23:33:20 +03:00
parent d57851c2d3
commit 2ed5b48067
2 changed files with 7 additions and 5 deletions

View file

@ -208,9 +208,9 @@
join-paths (fn [& paths]
(str/replace (str/replace (str/join "/" paths) #"([/]+)" "/") #"/$" ""))
response (fn [path]
(if-let [response (or (paths (join-paths "/" path))
(response-fn path options))]
(response/content-type response (mime-type/ext-mime-type path))))
(if-let [response (or (paths (join-paths "/" path))
(response-fn path options))]
(response/content-type response (mime-type/ext-mime-type path))))
path-or-index-response (fn [path uri]
(or (response path)
(loop [[file & files] index-files]
@ -221,8 +221,8 @@
handler (if path
(fn [request]
(let [uri (:uri request)]
(if-let [path (if (>= (count uri) path-size) (subs uri path-size))]
(path-or-index-response path uri))))
(if (.startsWith uri path)
(path-or-index-response (subs uri path-size) uri))))
(fn [request]
(let [uri (:uri request)
path (-> request :path-params parameter)]

View file

@ -491,6 +491,8 @@
(testing "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)))))
(testing "3-arity"