fix(rtrim): remove regex to prevent ReDOS attack by tux-tn · Pull Request #1738 · validatorjs/validator.js

This PR fixes a potential ReDOS in rtrim sanitizer. A try has been made in #1603 to fix the same vulnerability but it looks like we failed to prevent it.

The new implementation is not based on regex and is inspired by Steven Levithan's blog post and trim package implementation.

Thanks to @yetingli for discovering the vulnerability and huntr.dev for reporting it

Checklist

  • PR contains only changes related; no stray files, etc.