Sanitize get request routes


#1

Hey
My validation works fine on get requests using this piece of code:

class GetProduct {

    get rules () {
        return {
            id: 'required|existsInShop:products,id',
        }
    }

    get sanitizationRules () {
        return {
            id: `to_int`,
        }
    }

    get data () {
        const requestBody = this.ctx.request.params
        // const sessionId = this.ctx.request.header('X-Session-Id')

        return Object.assign({}, requestBody, {})
    }

    async fails (errorMessages) {
        return this.ctx.response.send(errorMessages)
    }

}

however, sanitization does not work.
Inside my controller when I log typeof request.params.id or typeof params.id , it returns string which should be number

I have to mention that this only happens in get requests. ( parameters in route url )

any help


#2

any help?
How do you sanitize parameters of your get requests ?
in above code, validation works but sanitization not.


#3

Closed in favour of https://github.com/adonisjs/adonis-framework/issues/948#issuecomment-422282961