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

Is checkExact() with wildcards supported? #1242

Open
pano9000 opened this issue Sep 7, 2023 · 4 comments · May be fixed by #1281
Open

Is checkExact() with wildcards supported? #1242

pano9000 opened this issue Sep 7, 2023 · 4 comments · May be fixed by #1281
Assignees
Labels

Comments

@pano9000
Copy link

pano9000 commented Sep 7, 2023

Hi all,

quick question: Is the checkExact() middleware supported for wildcards?

E.g. consider the following scenario:

I need to validate a body that looks something like this:

const body = [
  {
    id: 1,
    qty: 100
  },
  {
    id: 2,
    qty: 100
  }
]

-> So essentially an array of objects with an id and qty property.

I can nicely check for validity with the following chain

  body()
    .isArray(),

  body("*")
    .isObject(),

  body("*.id")
    .isInt(),

  body("*.qty")
    .isInt(),

Adding checkExact() to the end of the chain above however does not seem to cause the following example to fail validation, despite it having one additional unwanted property (wrong) in the second object:

const body = [
  {
    id: 1,
    qty: 100
  },
  {
    id: 2,
    wrong: 1,
    qty: 100
  }
]

So I wonder: is this scenario even supported currently, or am I running into a bug (or maybe I am doing something wrong?)

thanks in advance

Kind regards,

Pano

@vardana-bh
Copy link

Facing same challenge. checkExact does not work when request is validated for array level in checkSchema.

@CerealeZ
Copy link

CerealeZ commented Jan 7, 2024

Facing same problem here. I'm doing this:

app.post(
  "/signup",

  checkExact([
    body("addresses").isObject(),
    body("addresses.*.number").isInt(),
    body("siblings.*.name").notEmpty(),
  ]),
  (req, res) => {
    validationResult(req).throw()
    res.json({
      msg: "Sucess",
    })
  }
)

but there is no throwed error when I send this:

{
  "addresses": {
    "home": {
      "number": 35
    },
    "work": {
      "number": 501,
      "wrong": "yes"
    }
  },
  "siblings": [
    {
      "name": "Maria von Validator"
    },
    {
      "name": "Checky McCheckFace"
    }
  ]
}

@fedeci
Copy link
Member

fedeci commented Feb 21, 2024

I'm investigating

@FedericoBonel
Copy link

Hey! @fedeci @gustavohenke Just hit this same issue. Is there a current work around this? Or should I manually implement the exact check?

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

Successfully merging a pull request may close this issue.

5 participants