Skip to content

Commit

Permalink
fix: properly transform domain
Browse files Browse the repository at this point in the history
Fixes #2915
  • Loading branch information
Marsup committed Feb 21, 2023
1 parent cc88b68 commit 245e0c9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
8 changes: 4 additions & 4 deletions benchmarks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
10 changes: 10 additions & 0 deletions browser/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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);
});
});
2 changes: 1 addition & 1 deletion lib/types/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ internals.addressOptions = function (options) {

const allow = options.tlds.allow;
if (!allow) {
return options;
return { ...options, tlds: false };
}

if (allow === true) {
Expand Down

0 comments on commit 245e0c9

Please sign in to comment.