Skip to content

Commit

Permalink
13.5.2
Browse files Browse the repository at this point in the history
- patch fixing #1545 #1543 and #1544
- ref PR #1546 by @tux-tn
  • Loading branch information
profnandaa committed Dec 10, 2020
1 parent 4e3e51c commit b793beb
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 33 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "validator",
"description": "String validation and sanitization",
"version": "13.5.1",
"version": "13.5.2",
"sideEffects": false,
"homepage": "https://github.com/chriso/validator.js",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ import isStrongPassword from './lib/isStrongPassword';

import isVAT from './lib/isVAT';

const version = '13.5.1';
const version = '13.5.2';

const validator = {
version,
Expand Down
39 changes: 26 additions & 13 deletions src/lib/isFQDN.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,52 @@ export default function isFQDN(str, options) {
str = str.substring(0, str.length - 1);
}
const parts = str.split('.');
for (let i = 0; i < parts.length; i++) {
if (parts[i].length > 63) {
const tld = parts[parts.length - 1];

if (options.require_tld) {
// disallow fqdns without tld
if (parts.length < 2) {
return false;
}
}
if (options.require_tld) {
const tld = parts.pop();
if (!parts.length || !/^([a-z\u00a1-\uffff]{2,}|xn[a-z0-9-]{2,})$/i.test(tld)) {

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

// disallow spaces && special characers
if (/[\s\u2002-\u200B\u202F\u205F\u3000\uFEFF\uDB40\uDC20\u00A9\uFFFD]/.test(tld)) {
return false;
}
}
for (let part, i = 0; i < parts.length; i++) {
part = parts[i];
if (!options.allow_numeric_tld && i === parts.length - 1 && /^\d+$/.test(part)) {
return false; // reject numeric TLDs

// reject numeric TLDs
if (!options.allow_numeric_tld && /^\d+$/.test(tld)) {
return false;
}

return parts.every((part) => {
if (part.length > 63) {
return false;
}

if (!/^[a-z_\u00a1-\uffff0-9-]+$/i.test(part)) {
return false;
}

// disallow full-width chars
if (/[\uff01-\uff5e]/.test(part)) {
return false;
}
if (part[0] === '-' || part[part.length - 1] === '-') {

// disallow parts starting or ending with hyphen
if (/^-|-$/.test(part)) {
return false;
}

if (!options.allow_underscores && /_/.test(part)) {
return false;
}
}
return true;

return true;
});
}
3 changes: 3 additions & 0 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ describe('Validators', () => {
`${repeat('a', 31)}@gmail.com`,
'test@gmail.com',
'test.1@gmail.com',
'test@1337.com',
],
invalid: [
'invalidemail@',
Expand Down Expand Up @@ -374,6 +375,7 @@ describe('Validators', () => {
'http://[2010:836B:4179::836B:4179]',
'http://example.com/example.json#/foo/bar',
'http://user:@www.foobar.com',
'http://1337.com',
],
invalid: [
'http://localhost:3000/',
Expand Down Expand Up @@ -894,6 +896,7 @@ describe('Validators', () => {
'foo--bar.com',
'xn--froschgrn-x9a.com',
'rebecca.blackfriday',
'1337.com',
],
invalid: [
'abc',
Expand Down
36 changes: 19 additions & 17 deletions validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,31 +430,32 @@ function isFQDN(str, options) {
}

var parts = str.split('.');
var tld = parts[parts.length - 1];

for (var i = 0; i < parts.length; i++) {
if (parts[i].length > 63) {
if (options.require_tld) {
// disallow fqdns without tld
if (parts.length < 2) {
return false;
}
}

if (options.require_tld) {
var tld = parts.pop();

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


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


for (var part, _i = 0; _i < parts.length; _i++) {
part = parts[_i];
if (!options.allow_numeric_tld && /^\d+$/.test(tld)) {
return false;
}

if (!options.allow_numeric_tld && _i === parts.length - 1 && /^\d+$/.test(part)) {
return false; // reject numeric TLDs
return parts.every(function (part) {
if (part.length > 63) {
return false;
}

if (!/^[a-z_\u00a1-\uffff0-9-]+$/i.test(part)) {
Expand All @@ -464,18 +465,19 @@ function isFQDN(str, options) {

if (/[\uff01-\uff5e]/.test(part)) {
return false;
}
} // disallow parts starting or ending with hyphen

if (part[0] === '-' || part[part.length - 1] === '-') {

if (/^-|-$/.test(part)) {
return false;
}

if (!options.allow_underscores && /_/.test(part)) {
return false;
}
}

return true;
return true;
});
}

/**
Expand Down Expand Up @@ -4619,7 +4621,7 @@ function isVAT(str, countryCode) {
throw new Error("Invalid country code: '".concat(countryCode, "'"));
}

var version = '13.5.0';
var version = '13.5.2';
var validator = {
version: version,
toDate: toDate,
Expand Down
2 changes: 1 addition & 1 deletion validator.min.js

Large diffs are not rendered by default.

0 comments on commit b793beb

Please sign in to comment.