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 Oct 6, 2020
1 parent 279e771 commit d62d294
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 @@ -33,10 +33,7 @@ export default function isFQDN(str, options) {
}
for (let part, i = 0; i < parts.length; i++) {
part = parts[i];
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 @@ -46,6 +43,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 @@ -467,6 +467,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 d62d294

Please sign in to comment.