user1791219
user1791219

Reputation:

play-framework 2 how to escape colon in routes

in my play2 routes file, I am trying to use a colon as a literal:

GET     /:search                       controllers.SearchController.index()

but play complains, that a parameter is missing. How do I escape the colon (I tried backslashing it)?

thanks

Upvotes: 2

Views: 1121

Answers (1)

Samuel
Samuel

Reputation: 1667

You must introduce a dummy regex parameter, as such:

GET     /$colon<\:>search           controllers.SearchController.index(colon)

You must then also redefine your controller method:

public static Result index(String colon) {
 ....

The parser is built in such a way that path expressions cannot be escaped, save for this method.

Upvotes: 4

Related Questions