Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: properly transform domain #2916

Merged
merged 1 commit into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: properly transform domain
Fixes #2915
  • Loading branch information
Marsup committed Feb 21, 2023
commit 245e0c9b4a16bdb25425acc173a118fd8879a956
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