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

@ -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"