hapijs / joi

The most powerful data validation library for JS
Other
20.95k stars 1.51k forks source link

Email validate: Cannot read properties of undefined (reading 'has') #2918

Closed Jingjiasheng closed 1 year ago

Jingjiasheng commented 1 year ago

Support plan

Context

What are you trying to achieve or the steps to reproduce?

import * as Joi from "joi";

(()=>{

    const { value: sanitized, error:error } = Joi.string().email({
        tlds:{ allow:false },
        minDomainSegments: 1
    }).validate("aaa@bbb.com")

    console.error(error)

})()

What was the result you got?

/home/jing/code/demo/node_modules/@hapi/address/src/domain.ts:145
        } else if (tlds.deny.has(tld)) {
                             ^
TypeError: Cannot read properties of undefined (reading 'has')
    at analyzeDomain (/home/jing/code/demo/node_modules/@hapi/address/src/domain.ts:145:30)
    at validateEmail (/home/jing/code/demo/node_modules/@hapi/address/src/email.ts:90:56)
    at isEmailValid (/home/jing/code/demo/node_modules/@hapi/address/src/email.ts:39:13)
    at Object.validate (/home/jing/code/demo/node_modules/joi/lib/types/string.js:296:26)
    at Object.internals.rules (/home/jing/code/demo/node_modules/joi/lib/validator.js:397:33)
    at Object.exports.validate (/home/jing/code/demo/node_modules/joi/lib/validator.js:353:22)
    at Object.internals.entry (/home/jing/code/demo/node_modules/joi/lib/validator.js:145:28)
    at Object.exports.entry (/home/jing/code/demo/node_modules/joi/lib/validator.js:27:30)
    at internals.Base.validate (/home/jing/code/demo/node_modules/joi/lib/base.js:548:26)
    at /home/jing/code/demo/joi.ts:8:8

What result did you expect?

undefined will be better

There are no problems in the v17.8.2

Marsup commented 1 year ago

Duplicate of https://github.com/hapijs/joi/issues/2915. Upgrade to 17.8.3.