weavejester / compojure

A concise routing library for Ring/Clojure
Eclipse Public License 1.0
4.09k stars 256 forks source link

Cannot escape colons in the route #161

Closed alvinfrancis closed 7 years ago

alvinfrancis commented 7 years ago

Currently, there doesn't seem to be any way to have a colon in the route. It would be useful to have an easy way to escape colons when you want colons as part of the route path instead of being used for URI matching; colons being valid characters for URLs.

weavejester commented 7 years ago

You can escape colons. Just use \:

user=> (use 'compojure.core)
nil
user=> (def r (GET "/\\:foo" [] "foo"))
#'user/r
user=> (r {:request-method :get, :uri "/:foo"})
{:status 200, :headers {"Content-Type" "text/html; charset=utf-8"}, :body "foo"}
user=> (r {:request-method :get, :uri "/foo"})
nil
alvinfrancis commented 7 years ago

Ah. My bad. I was having a problem with regards to it using compojure-api. In particular, the swagger ui was incorrectly showing the URI matches no matter what sort of escaping I did on the colons. I had thought that since it was built on top of this library, the problem would be here. It looks like it's purely on its swagger ui code though since it's matching it properly.

Thanks for the help!