Grails Method to Prevent Invalid Request for "Identifiers" at URL

Like here in stackoverflow, if I force bad characters into the url in id, it redirects you to a page error. I would like to know if with Grails it has some kind of plugin to prevent id: "123 $ # 3" or an easy way because I have a lot of actions and something like below seems to be not the best way: / p >


def find = {   

     def val = OwnStringUtilsClass.verify(params.id)
     val ? Book.get(val) : response.sendError(404)
}
+3
source share
2 answers

You can use the following in grails-app/conf/UrlMappings.groovy:

  "/$controller/$action?/$id?"{
          constraints {
                    id(matches:/\d*/)
              }
      }

This ensures that it idis numeric.

+3
source

.

0

Source: https://habr.com/ru/post/1729408/


All Articles