Repository: hapijs/joi (JavaScript)

Issue:
Email validation error in v17.8.1
#### Support plan

* *is this issue currently blocking your project?* (yes/no): no
* *is this issue affecting a production system?* (yes/no): no

#### Context

* *node version*: v18.0
* *module version*: v17.8.1
* *environment* (e.g. node, browser, native): browser 
* *used with* (e.g. hapi application, another framework, standalone, ...): hapi
* *any other relevant information*:

#### What are you trying to achieve or the steps to reproduce?

## Schema
```js
Joi.object({
  email: Joi.string()
        .email({ tlds: { allow: false } })
})
```
## Data To Validate
```js
{ 
  email: 'somevalid@email.com'
}
```

## Result
```
TypeError: Cannot read properties of undefined (reading 'has')
```

#### What result did you expect?
Validate without error as stated on https://joi.dev/api/?v=17.8.1#stringemailoptions
 


Discussion:
I'm getting same with v17.8.1 and v17.8.0 and the same schema:
```js
Joi.object({
  email: Joi.string()
        .email({ tlds: { allow: false } })
})
```

Fixed by pinning at 17.7.1.

Bug must have been caused by https://github.com/hapijs/joi/pull/2909
This is fixed in 17.8.2.



Patch:
diff --git a/benchmarks/package.json b/benchmarks/package.json
index 62b50609..7d195472 100644
--- a/benchmarks/package.json
+++ b/benchmarks/package.json
@@ -7,13 +7,13 @@
     "full-bench": "npm run bench-update -- --joi @hapi/joi && npm test"
   },
   "dependencies": {
-    "@hapi/bossy": "^4.0.3",
-    "@hapi/hoek": "^6.2.4",
+    "@hapi/bossy": "^6.0.1",
+    "@hapi/hoek": "^11.0.2",
     "@hapi/joi": "^15.1.0",
     "benchmark": "^2.1.4",
     "chalk": "^2.4.1",
-    "cli-table": "^0.3.1",
+    "cli-table": "^0.3.11",
     "d3-format": "^1.3.2",
-    "joi": "^17.6.4"
+    "joi": "^17.8.1"
   }
 }
diff --git a/lib/types/string.js b/lib/types/string.js
index 36baa2d4..81b3f946 100755
--- a/lib/types/string.js
+++ b/lib/types/string.js
@@ -772,7 +772,7 @@ internals.addressOptions = function (options) {
 
     const allow = options.tlds.allow;
     if (!allow) {
-        return options;
+        return { ...options, tlds: false };
     }
 
     if (allow === true) {


Test patch:
diff --git a/browser/tests/index.js b/browser/tests/index.js
index 071c0759..d5940371 100755
--- a/browser/tests/index.js
+++ b/browser/tests/index.js
@@ -34,6 +34,11 @@ describe('Joi', () => {
         Assert.ok(!schema.validate('test@example.com').error);
         Assert.ok(schema.validate('test@example.com ').error);
         Assert.ok(!schema.validate('伊昭傑@郵件.商務').error);
+
+        const schema2 = Joi.string().email({ tlds: { allow: false } }).required();
+        Assert.ok(!schema2.validate('test@example.com').error);
+        Assert.ok(schema2.validate('test@example.com ').error);
+        Assert.ok(!schema2.validate('伊昭傑@郵件.商務').error);
     });
 
     it('validates domain', () => {
@@ -42,5 +47,10 @@ describe('Joi', () => {
         Assert.ok(!schema.validate('example.com').error);
         Assert.ok(schema.validate('example.com ').error);
         Assert.ok(!schema.validate('example.商務').error);
+
+        const schema2 = Joi.string().domain({ tlds: { allow: false } }).required();
+        Assert.ok(!schema2.validate('example.com').error);
+        Assert.ok(schema2.validate('example.com ').error);
+        Assert.ok(!schema2.validate('example.商務').error);
     });
 });