question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Chaining validators and sanitizers

See original GitHub issue

Instead of this:

    request.sanitize('developer').toInt()
    request.sanitize('charity').toInt()
    request.sanitize('email').trim()
    request.sanitize('payform').trim()
    request.sanitize('mixpanel_id').trim()
    request.check('developer').isInt(min:0)
    request.check('charity').optional().isInt(min:0)
    request.check('email').trim().isEmail().isByteLength(0, 120)
    request.check('payform').isByteLength(0, 120)
    request.check('mixpanel_id').isByteLength(0, 120)

One could write this:

    request.validator('developer').isInt(min:0).toInt()
    request.validator('charity').optional().isInt(min:0).toInt()
    request.validator('email').trim().isEmail().isByteLength(0, 120)
    request.validator('payform').trim().isByteLength(0, 120)
    request.validator('mixpanel_id').trim().isByteLength(0, 120)

Possible to implement this enhancement?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
rustybaileycommented, Jan 20, 2016

That could work. You would just need to account for name conflicts if someone accidentally creates a custom sanitizer/validator with the same name.

0reactions
lock[bot]commented, Jun 2, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Validation Chain API - express-validator
The validation chain is a middleware, and it should be passed to an Express route handler. You can add as many validators and...
Read more >
Express-validator's default sanitizer doesn't work when chained
I am having trouble using the default() sanitizer from express-validator. When I use it in a chain, such as body("children").optional().
Read more >
chain-validator-js - npm
Easy to integrate validator.js based validation with chain syntax, informative validation result, unwanted data cutting and sanitizing.
Read more >
Chain order in schema · Issue #582 · express-validator ...
Is there a way to execute sanitizers and validators in the same order as they listed in schema? Here I have schema: const...
Read more >
How to Use express-validator in Combination with Schema ...
Lastly, if you have to add some custom validations on top of this schema-based validation, then you can do that too. You can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found