Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checkSchema field option--withMessage fails silently #664

Closed
recyclingben opened this issue Dec 6, 2018 · 1 comment
Closed

checkSchema field option--withMessage fails silently #664

recyclingben opened this issue Dec 6, 2018 · 1 comment
Labels
Milestone

Comments

@recyclingben
Copy link

recyclingben commented Dec 6, 2018

Had a bit of trouble coming up with a good title, so I'll just explain.
this:

checkSchema({
    exists: {
        in: "query",
        isInt: true,
        couchPotato: "hello!"
    }
})

results in the warning message express-validator: a validator with name couchPotato does not exist as intented. However, this:

checkSchema({
    exists: {
        in: "query",
        isInt: true,
        withMessage: "hello!"
    }
})

produces no warning message, which could lead a lot of newcomers confused, not understand an errorMessage property should be used instead.

The issue can be trached to these lines in schema.js:

if (typeof chain[method] !== 'function') {
    console.warn(`express-validator: a validator with name ${method} does not exist`);
    return;
}

As you can see, it is checking whether or not a method withMessage is available on the chain. This may technically be predictable behavior, as you can get withMessage working by doing this:

checkSchema({
    exists: {
        in: "query",
        isInt: true,
        withMessage: {
            options: "hello!"
        }
    }
})

but this can still lead to potential issues later if more non-validator methods are worked in.

I would be happy to submit a fix for this.

@gustavohenke
Copy link
Member

Hello @recyclingben!
Thanks for tracking this one down 😃 I'm happy to have you fix it, if you have the time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants