validatorjs / validator.js

String validation
MIT License
23.15k stars 2.32k forks source link

isFQDN function continues executing with disabled require_tld option #2425

Open mdss-single opened 5 months ago

mdss-single commented 5 months ago

Describe the bug The email is invalid if domain part is bigger than 63 symbols

Examples

// Current behaviour:
const email = test@1234567890123456789012345678901234567890123456789012345678901234.com;
console.log(validator.isEmail(email, {require_tld: false})); // => false

// Expected behaviour:
const email = test@1234567890123456789012345678901234567890123456789012345678901234.com;
console.log(validator.isEmail(email, {require_tld: false})); // => true

Additional context Validator.js version: 13.12.0 Node.js version: 18.18.0 OS platform: macOS

arjitcodes commented 5 months ago

For your expected behaviour you need to add option "ignore_max_length" with value "true"


// After add {gnore_max_length: true} :
const email = test@1234567890123456789012345678901234567890123456789012345678901234.com;
console.log(validator.isEmail(email, {require_tld: false, ignore_max_length: true})); // => true
mdss-single commented 5 months ago

For your expected behaviour you need to add option "ignore_max_length" with value "true"

// After add {gnore_max_length: true} :
const email = test@1234567890123456789012345678901234567890123456789012345678901234.com;
console.log(validator.isEmail(email, {require_tld: false, ignore_max_length: true})); // => true

In this case, that part of the code would be unreachable. My main idea is to validate the email according to the RFC standard, but with any configuration, it is impossible

  if (options.ignore_max_length === false && (
    !isByteLength(user, { max: 64 }) ||
    !isByteLength(domain, { max: 254 }))
  ) {
    return false;
  }