Route Validator not working well on Update

Hi.
I’m having problems with on route validator. This happens with regex validation, with sanitization and with custom validations. If I do the same validations on the Controller the problem doesn’t occur.

routes.js:

  Route
  .resource('companies','CompanyController')
  .validator(new Map([
    [['companies.store'], ['StoreCompany']],
    [['companies.update'], ['UpdateCompany']]
  ]))
The StoreCompany validator works good and is almost the same than update.


UpdateCompany.js

get rules () {
    return {
      name:[
        rule('min',7),
        rule('max',35),
        rule('regex',/^[a-zA-Z0-9,. ]+$/)
      ],
}
  get sanitizationRules () {
    return {
      name:'strip_tags',
      short_name:'escape',
      short_description:'escape',
    }

With this the regex rule just doesn’t work. Neither the sanitization rules.

But when I put the validation on the CompanyController it works:

async update ({ params, request, response, guard, auth }) {
    const { validate, rule} = use('Validator')

    const rules = {
      name:[
        rule('min',7),
        rule('max',35),
        rule('regex',/^[a-zA-Z0-9,. ]+$/)
      ]
    }

    const messages = {
      'name.regex':'Solo se permiten letras, numeros, espacio y puntos.'
    }
    const validation = await validate(request.all(), rules, messages)
...
}

Can you check it?

1 Like

@jorgeyoma Hi!

Can you try this please?