From c605fe6d63bacd6f0ae89890d87f85050d10de5a Mon Sep 17 00:00:00 2001 From: Oswaldo Date: Sun, 13 Mar 2022 00:04:08 -0600 Subject: [PATCH] fix: option allow_numeric_tld option in isFQDN --- src/lib/isFQDN.js | 2 +- test/validators.js | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/lib/isFQDN.js b/src/lib/isFQDN.js index 4a04cf34e..884d1dd6f 100644 --- a/src/lib/isFQDN.js +++ b/src/lib/isFQDN.js @@ -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; } diff --git a/test/validators.js b/test/validators.js index 61ffe09d9..dcac6ecab 100644 --- a/test/validators.js +++ b/test/validators.js @@ -1291,7 +1291,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',