Skip to content

A sanitizer should run at its place in the chain? #616

@slimee

Description

@slimee

hi, using 5.3.0, thanks you for making a love library

I saw #571 related and closed by f1f57d5 but I face the problem today.
Maybe it's not isMongoId do not break the chain, but the sanitizer that do not run at its place in the chain.

Does this chain sounds goods for you? _id must be a present objectID string, and after is sanitized as an objectID.

check("_id").exists().withMessage("missing")
    .isMongoId().withMessage("invalid")
    .customSanitizer(id => new mongo.ObjectID(id));

OK test with posting {name:"bryan"}
=>exists break the chain.
"errors": { "_id": { "location": "body", "param": "_id", "msg": "missing" } }

OK test with posting {_id:"5b574e725013c9f90a24af99",name:"bryan"}
=> The request continues with _id as an objectID.

KO test with posting {_id:"BAD_ID",name:"bryan"}
=>It causes an exception about the ObjectID constructor claiming the format is KO.
The sanitizer should not run since the isMongoId validator is KO?

Another test: if I remove the customSanitizer and send {_id:"BAD_ID",name:"bryan"} again, the isMongoId validation error occurs as expected.

Don't know where is the bug can you help?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions