Skip to content

Commit

Permalink
fix(isFQDN): allow all-underscore labels with allow_underscores (#1253)
Browse files Browse the repository at this point in the history
  • Loading branch information
gibson042 committed Nov 16, 2020
1 parent a19ebff commit 06b1a42
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/lib/isFQDN.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ export default function isFQDN(str, options) {
if (!options.allow_numeric_tld && i === parts.length - 1 && /^\d+$/.test(part)) {
return false; // reject numeric TLDs
}
if (options.allow_underscores) {
part = part.replace(/_/g, '');
}
if (!/^[a-z\u00a1-\uffff0-9-]+$/i.test(part)) {
if (!/^[a-z_\u00a1-\uffff0-9-]+$/i.test(part)) {
return false;
}
// disallow full-width chars
Expand All @@ -50,6 +47,9 @@ export default function isFQDN(str, options) {
if (part[0] === '-' || part[part.length - 1] === '-') {
return false;
}
if (!options.allow_underscores && /_/.test(part)) {
return false;
}
}
return true;
}
1 change: 1 addition & 0 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ describe('Validators', () => {
'http://foo_bar.com',
'http://pr.example_com.294.example.com/',
'http://foo__bar.com',
'http://_.example.com',
],
invalid: [],
});
Expand Down

0 comments on commit 06b1a42

Please sign in to comment.