Tom Brunoli
Tom Brunoli

Reputation: 3476

Commas in Compojure routes

I'm trying to create a route that has a parameter which contains commas in compojure

(GET "/tags/multiple/:tag-names" [tag-names] multiple-tags)

but for some reason, whenever I include a comma in the :tag-names field, it 404s. It works fine when there are no commas.

Does anyone know what causes this and how I can work around it?

Upvotes: 4

Views: 284

Answers (1)

mtyaka
mtyaka

Reputation: 8848

Compojure uses clout for routing. From clout's README:

Clout supports both keywords and wildcards. Keywords (like :title) will match any character but the following: / . , ; ?.

By default, clout treats commas as path segment separators. You can work around that by passing a custom regex to the route. The following would make :tag-names match any character except /:

(GET ["/tags/multiple/:tag-names" :tag-names #"[^/]+"] [tag-names] multiple-tags)

Upvotes: 5

Related Questions