Fork me on GitHub
#reitit
<
2018-11-20
>
jaide17:11:42

Currently if you visit /api/leads/ with a trailing slash the app breaks because id is an empty string. How should I fortify my routes?

jaide17:11:20

One option would be to test if id is empty and then do (layout/error-page {:status 404 title: "404 - Page not found"} but I’m curious if there’s a better way.

ikitommi17:11:53

@jayzawrotny bug in routing? I think the empty path parameter should not match to the path-parameter route?

ikitommi17:11:53

(require '[compojure.core :as c])

((c/GET "/kikka/:id" [] "kikka") {:request-method :get, :uri "/kikka/1"})
; => {:status 200, :headers {"Content-Type" "text/html; charset=utf-8"}, :body "kikka"}

((c/GET "/kikka/:id" [] identity) {:request-method :get, :uri "/kikka/"})
; => nil

jaide17:11:52

I’m not sure. I didn’t expect it to match but it does.

jaide17:11:06

The value of my id in line 16 is an empty string ""

ikitommi17:11:06

could you write an issue out of that?

ikitommi17:11:34

yes, it’s a bug. tested with both compojure & bidi, both don’t match on empty path parameter.

jaide17:11:30

Sure thing