Skip to content

Commit

Permalink
feat(isFQDN): fix tld validation (#1091)
Browse files Browse the repository at this point in the history
* feat(isFQDN): fix tld validation

* feat(isFQDN): fix tld validation

* fix: combine two instruction into one

* fix: run testing commands

Co-authored-by: Amine <[email protected]>
  • Loading branch information
alouini333 and Amine authored Mar 22, 2020
1 parent 4db2711 commit 2a3ad84
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var version = '13.0.0';
Expand Down
4 changes: 2 additions & 2 deletions lib/isFQDN.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ function isFQDN(str, options) {

if (!parts.length || !/^([a-z\u00a1-\uffff]{2,}|xn[a-z0-9-]{2,})$/i.test(tld)) {
return false;
} // disallow spaces
} // disallow spaces && special characers


if (/[\s\u2002-\u200B\u202F\u205F\u3000\uFEFF\uDB40\uDC20]/.test(tld)) {
if (/[\s\u2002-\u200B\u202F\u205F\u3000\uFEFF\uDB40\uDC20\u00A9\uFFFD]/.test(tld)) {
return false;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/isFQDN.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export default function isFQDN(str, options) {
if (!parts.length || !/^([a-z\u00a1-\uffff]{2,}|xn[a-z0-9-]{2,})$/i.test(tld)) {
return false;
}
// disallow spaces
if (/[\s\u2002-\u200B\u202F\u205F\u3000\uFEFF\uDB40\uDC20]/.test(tld)) {
// disallow spaces && special characers
if (/[\s\u2002-\u200B\u202F\u205F\u3000\uFEFF\uDB40\uDC20\u00A9\uFFFD]/.test(tld)) {
return false;
}
}
Expand Down
4 changes: 4 additions & 0 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ describe('Validators', () => {
'[email protected]',
'wrong()[]",:;<>@@gmail.com',
'"wrong()[]",:;<>@@gmail.com',
'[email protected]�',
'[email protected]©',
],
});
});
Expand Down Expand Up @@ -829,6 +831,8 @@ describe('Validators', () => {
's!ome.com',
'domain.com/',
'/more.com',
'domain.com�',
'domain.com©',
],
});
});
Expand Down
4 changes: 2 additions & 2 deletions validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,10 @@ function isFQDN(str, options) {

if (!parts.length || !/^([a-z\u00a1-\uffff]{2,}|xn[a-z0-9-]{2,})$/i.test(tld)) {
return false;
} // disallow spaces
} // disallow spaces && special characers


if (/[\s\u2002-\u200B\u202F\u205F\u3000\uFEFF\uDB40\uDC20]/.test(tld)) {
if (/[\s\u2002-\u200B\u202F\u205F\u3000\uFEFF\uDB40\uDC20\u00A9\uFFFD]/.test(tld)) {
return false;
}
}
Expand Down

0 comments on commit 2a3ad84

Please sign in to comment.