What Does the Express-Validator Escape() Function?

What Does the Express-Validator Escape() Function?

What exactly does the express-validator escape() sanitizer? Can't understand. For example:

check('name')
  .trim()
  .escape()
  .notEmpty()
  .withMessage('User name can not be empty!')
  .bail()
  .isLength({ min: 3 })
  .withMessage('Minimum 3 characters required!')
  .bail(),

Why there is a need to escape() after trim()?

1

2 Answers

Thanks to robertklep. Every sanitizer is described here:

Sanitizers

Interestingly, it replace <, >, &, ', " and / with HTML entities.

You may refer here: validatorjs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Sarah Jenkins
Author

Sarah Jenkins

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.