Skip to content

Commit

Permalink
Merge pull request #1939 from BigOsvaap/fix-isFQDN-allow_numeric_tld-…
Browse files Browse the repository at this point in the history
…option

fix(isFQDN): allow_numeric_tld option didn't work
  • Loading branch information
rubiin authored Jul 17, 2022
2 parents c57ff39 + c605fe6 commit 8f04ca9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/lib/isFQDN.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function isFQDN(str, options) {
return false;
}

if (!/^([a-z\u00A1-\u00A8\u00AA-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{2,}|xn[a-z0-9-]{2,})$/i.test(tld)) {
if (!options.allow_numeric_tld && !/^([a-z\u00A1-\u00A8\u00AA-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{2,}|xn[a-z0-9-]{2,})$/i.test(tld)) {
return false;
}

Expand Down
13 changes: 12 additions & 1 deletion test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -1309,7 +1309,18 @@ describe('Validators', () => {
],
});
});

it('should validate FQDN with required allow_trailing_dot, allow_underscores and allow_numeric_tld options', () => {
test({
validator: 'isFQDN',
args: [
{ allow_trailing_dot: true, allow_underscores: true, allow_numeric_tld: true },
],
valid: [
'abc.efg.g1h.',
'as1s.sad3s.ssa2d.',
],
});
});
it('should validate alpha strings', () => {
test({
validator: 'isAlpha',
Expand Down

0 comments on commit 8f04ca9

Please sign in to comment.