Skip to content

[release staging] April 2021 Release (v13.6.0) #1650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 46 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
4e3e51c
13.5.1
profnandaa Nov 30, 2020
0b0b4e9
fix: update v on changelog
profnandaa Dec 1, 2020
9dc4ed3
feat(isMobilePhone): add ar-OM locale (#1506)
dev-sna Dec 1, 2020
5810e36
feat(isVAT): add IT locale (#1536)
fedeci Dec 2, 2020
302d295
fix(isMobilePhone): update es-CO locale (#1541)
ezkemboi Dec 3, 2020
dc05855
feat(isMobilePhone): add pt-AO locale (#1505)
AdilsonFuxe Dec 8, 2020
3358f45
fix(isFQDN): numeric domain names (#1546)
tux-tn Dec 8, 2020
787df19
fix(isBtcAddress): add base58 (#1548)
ezkemboi Dec 9, 2020
738cf60
feat(isMobilePhone): update de-CH, add fr-CH, it-CH locales (#1554)
Dec 17, 2020
edcd161
feat(isLicensePlate): new validator 🎉 (#1495)
firlus Dec 17, 2020
8831db3
fix(isTaxID): fix el-GR locale when checksum is 10 (#1529)
dspinellis Dec 17, 2020
1b85829
feat(isMobileNumber): add support new telco numbers for VN locale (#1…
kyled7 Jan 14, 2021
9b03daf
feat(isStrongPassword): add `@` as valid symbol (#1566)
stingalleman Feb 15, 2021
941abe1
chore: setup github actions (#1606)
tux-tn Feb 26, 2021
b685d55
chore: refactor code in isDataURI validator (#1556)
ezkemboi Feb 26, 2021
ae9a311
chore: add a more explanatory description to CI jobs (#1617)
tux-tn Feb 26, 2021
de48970
fix(isMacAddress): improve regexes and options (#1616)
fedeci Feb 26, 2021
2331120
feat: added Libya Passport and Identity Number Validation (#1583)
asghaier76 Feb 28, 2021
6d87bfe
fix(isSlug & rtrim): regex no longer exposed to ReDOS attacks (#1603)
fedeci Mar 3, 2021
328dea0
chore: add `isSlug` test cases (#1602)
fedeci Mar 3, 2021
022b100
chore(docs): rephrase sentence for grammatical correctness (#1620)
prahaladbelavadi Mar 3, 2021
deb1d1e
feat(isEAN, isAlphanumeric): add support for EAN-14 and sAlphanumeric…
varsubham Mar 3, 2021
6262f62
chore: improving code coverage to 100% branches (#1624)
renanmontebelo Mar 12, 2021
418df05
fix(isMobilePhone): prevent allowing landline numbers in es-CO (#1623)
tux-tn Mar 12, 2021
3c771e8
feat(pt-BR): tax id, passport and license plates (#1613)
mschunke Mar 12, 2021
7989e5b
feat(isLicensePlate): add support for pt-BR locale (#1588)
renanmontebelo Mar 12, 2021
bb0dba6
feat(isPassportNumber): add MY locale (#1574)
stranger26 Mar 12, 2021
63b6162
chore: add gitter chatroom badge (#1592)
profnandaa Mar 14, 2021
a31c116
fix: update isMobilePhone validation for en-SG (#1573)
liliwei25 Apr 13, 2021
5d6db63
feat(isIPRange): add support for IP version 4 or 6 (#1594)
neilime Apr 17, 2021
39830a9
feat: IR passport and identityCard, respect .gitignore files (#1595)
mhf-ir Apr 17, 2021
b65ddc5
fix: fix A-z ranges (#1625)
bmacnaughton Apr 17, 2021
67a200d
feat(isPostalCode): add KR locale (#1628)
greatSumini Apr 17, 2021
2ef84e4
fix(isIP): validator patterns for IPv4 and IPv6 RegExp formats (#1632)
ognjenjevremovic Apr 17, 2021
c33fca6
fix(isISIN): optimization (#1633)
bmacnaughton Apr 17, 2021
d006e08
fix(isMobilePhone): add support for new networks codes in GH (#1635)
ankorGH Apr 17, 2021
615547f
feat(isMobilePhone): add Latvia lv-LV locale (#1638)
AntonLukichev Apr 17, 2021
b82f4f2
fix(docs): typo in README.md (#1640)
fedeci Apr 17, 2021
9ee1b6b
fix(isMobilePhone): update china zh-CN locale (#1642)
Akira0705 Apr 17, 2021
05ceb18
isURL(): Allow URLs to have only a username in the userinfo subcompon…
jbuchmann-coosto Apr 17, 2021
3f70b8e
feat(isPassportNumber, isIBAN, isMobilePhone): add Mozambique locale …
salmento Apr 18, 2021
cf403d0
fix(isMobilePhone): add Sierra Leone phone and fix Sri Lanka phone (#…
ezkemboi Apr 18, 2021
1fa0959
chore: add typeof utility (#1648)
ezkemboi Apr 18, 2021
2a3a1c3
13.6.0
profnandaa Apr 18, 2021
b986f3d
fix: ReDOS in isEmail and isHSL (#1651)
tux-tn Apr 20, 2021
24b3fd3
13.6.1
profnandaa Apr 20, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: CI
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
test:
runs-on: ubuntu-20.04
strategy:
matrix:
node-version: [14, 12, 10, 8, 6]
name: Run tests on Node.js ${{ matrix.node-version }}
steps:
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2-beta
with:
node-version: ${{ matrix.node-version }}
check-latest: true
- name: Checkout repository
uses: actions/checkout@v2
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
- if: matrix.node-version == 14
name: Generate coverage file
run: npm run test:ci > coverage.lcov
- if: matrix.node-version == 14
name: Send coverage info to Codecov
uses: codecov/codecov-action@v1
with:
file: ./coverage.lcov
24 changes: 24 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: NPM Publish
on:
release:
types: [created]
jobs:
publish:
runs-on: ubuntu-20.04
steps:
- name: Setup Node.js 14
uses: actions/setup-node@v2-beta
with:
node-version: 14
check-latest: true
registry-url: https://registry.npmjs.org/
- name: Checkout Repository
uses: actions/checkout@v2
- name: Install Dependencies
run: npm install
- name: Run Tests
run: npm test
- name: Publish Package to NPM Registry
run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_SECRET}}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ package-lock.json
yarn.lock
/es
/lib
/index.js
validator.js
validator.min.js
index.js
4 changes: 0 additions & 4 deletions .nycrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,5 @@
],
"include": [
"src/**/*.js"
],
"exclude": [
"validator.js",
"lib/**/*.js"
]
}
14 changes: 0 additions & 14 deletions .travis.yml

This file was deleted.

656 changes: 350 additions & 306 deletions CHANGELOG.md

Large diffs are not rendered by default.

43 changes: 24 additions & 19 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "validator-js",
"main": "validator.js",
"homepage": "https://github.com/chriso/validator.js",
"homepage": "https://github.com/validatorjs/validator.js",
"authors": [
"Chris O'Hara <cohara87+gh@gmail.com>"
],
Expand Down
15 changes: 6 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "validator",
"description": "String validation and sanitization",
"version": "13.5.0",
"version": "13.6.0",
"sideEffects": false,
"homepage": "https://github.com/chriso/validator.js",
"homepage": "https://github.com/validatorjs/validator.js",
"files": [
"index.js",
"es",
Expand All @@ -25,18 +25,15 @@
],
"author": "Chris O'Hara <cohara87@gmail.com>",
"contributors": [
{
"name": "Anthony Nandaa",
"url": "https://github.com/profnandaa"
}
"Anthony Nandaa (https://github.com/profnandaa)"
],
"main": "index.js",
"bugs": {
"url": "https://github.com/chriso/validator.js/issues"
"url": "https://github.com/validatorjs/validator.js/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/chriso/validator.js.git"
"url": "git+https://github.com/validatorjs/validator.js.git"
},
"devDependencies": {
"@babel/cli": "^7.0.0",
Expand All @@ -48,7 +45,7 @@
"eslint": "^4.19.1",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-plugin-import": "^2.11.0",
"mocha": "^5.1.1",
"mocha": "^6.2.3",
"nyc": "^14.1.0",
"rimraf": "^3.0.0",
"rollup": "^0.43.0",
Expand Down
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,12 @@ import isWhitelisted from './lib/isWhitelisted';
import normalizeEmail from './lib/normalizeEmail';

import isSlug from './lib/isSlug';
import isLicensePlate from './lib/isLicensePlate';
import isStrongPassword from './lib/isStrongPassword';

import isVAT from './lib/isVAT';

const version = '13.5.0';
const version = '13.6.0';

const validator = {
version,
Expand Down Expand Up @@ -219,6 +220,7 @@ const validator = {
isStrongPassword,
isTaxID,
isDate,
isLicensePlate,
isVAT,
};

Expand Down
18 changes: 16 additions & 2 deletions src/lib/isAlphanumeric.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
import assertString from './util/assertString';
import { alphanumeric } from './alpha';

export default function isAlphanumeric(str, locale = 'en-US') {
assertString(str);
export default function isAlphanumeric(_str, locale = 'en-US', options = {}) {
assertString(_str);

let str = _str;
const { ignore } = options;

if (ignore) {
if (ignore instanceof RegExp) {
str = str.replace(ignore, '');
} else if (typeof ignore === 'string') {
str = str.replace(new RegExp(`[${ignore.replace(/[-[\]{}()*+?.,\\^$|#\\s]/g, '\\$&')}]`, 'g'), ''); // escape regex for ignore
} else {
throw new Error('ignore should be instance of a String or RegExp');
}
}

if (locale in alphanumeric) {
return alphanumeric[locale].test(str);
}
Expand Down
11 changes: 10 additions & 1 deletion src/lib/isBIC.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import assertString from './util/assertString';
import { CountryCodes } from './isISO31661Alpha2';

const isBICReg = /^[A-z]{4}[A-z]{2}\w{2}(\w{3})?$/;
// https://en.wikipedia.org/wiki/ISO_9362
const isBICReg = /^[A-Za-z]{6}[A-Za-z0-9]{2}([A-Za-z0-9]{3})?$/;

export default function isBIC(str) {
assertString(str);

// toUpperCase() should be removed when a new major version goes out that changes
// the regex to [A-Z] (per the spec).
if (CountryCodes.indexOf(str.slice(4, 6).toUpperCase()) < 0) {
return false;
}

return isBICReg.test(str);
}
9 changes: 7 additions & 2 deletions src/lib/isBtcAddress.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import assertString from './util/assertString';

// supports Bech32 addresses
const btc = /^(bc1|[13])[a-zA-HJ-NP-Z0-9]{25,39}$/;
const bech32 = /^(bc1)[a-z0-9]{25,39}$/;
const base58 = /^(1|3)[A-HJ-NP-Za-km-z1-9]{25,39}$/;

export default function isBtcAddress(str) {
assertString(str);
return btc.test(str);
// check for bech32
if (str.startsWith('bc1')) {
return bech32.test(str);
}
return base58.test(str);
}
7 changes: 4 additions & 3 deletions src/lib/isDataURI.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ export default function isDataURI(str) {
return false;
}
for (let i = 0; i < attributes.length; i++) {
if (i === attributes.length - 1 && attributes[i].toLowerCase() === 'base64') {
// ok
} else if (!validAttribute.test(attributes[i])) {
if (
!(i === attributes.length - 1 && attributes[i].toLowerCase() === 'base64') &&
!validAttribute.test(attributes[i])
) {
return false;
}
}
Expand Down
17 changes: 11 additions & 6 deletions src/lib/isEAN.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,25 @@
* the thirteen-digit EAN-13, while the
* less commonly used 8-digit EAN-8 barcode was
* introduced for use on small packages.
* Also EAN/UCC-14 is used for Grouping of individual
* trade items above unit level(Intermediate, Carton or Pallet).
* For more info about EAN-14 checkout: https://www.gtin.info/itf-14-barcodes/
* EAN consists of:
* GS1 prefix, manufacturer code, product code and check digit
* Reference: https://en.wikipedia.org/wiki/International_Article_Number
* Reference: https://www.gtin.info/
*/

import assertString from './util/assertString';

/**
* Define EAN Lenghts; 8 for EAN-8; 13 for EAN-13
* and Regular Expression for valid EANs (EAN-8, EAN-13),
* with exact numberic matching of 8 or 13 digits [0-9]
* Define EAN Lenghts; 8 for EAN-8; 13 for EAN-13; 14 for EAN-14
* and Regular Expression for valid EANs (EAN-8, EAN-13, EAN-14),
* with exact numberic matching of 8 or 13 or 14 digits [0-9]
*/
const LENGTH_EAN_8 = 8;
const validEanRegex = /^(\d{8}|\d{13})$/;
const LENGTH_EAN_14 = 14;
const validEanRegex = /^(\d{8}|\d{13}|\d{14})$/;


/**
Expand All @@ -28,7 +33,7 @@ const validEanRegex = /^(\d{8}|\d{13})$/;
* @return {number}
*/
function getPositionWeightThroughLengthAndIndex(length, index) {
if (length === LENGTH_EAN_8) {
if (length === LENGTH_EAN_8 || length === LENGTH_EAN_14) {
return (index % 2 === 0) ? 3 : 1;
}

Expand Down Expand Up @@ -56,7 +61,7 @@ function calculateCheckDigit(ean) {

/**
* Check if string is valid EAN:
* Matches EAN-8/EAN-13 regex
* Matches EAN-8/EAN-13/EAN-14 regex
* Has valid check digit.
*
* @param {string} str
Expand Down
16 changes: 9 additions & 7 deletions src/lib/isEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const default_email_options = {

/* eslint-disable max-len */
/* eslint-disable no-control-regex */
const splitNameAddress = /^([^\x00-\x1F\x7F-\x9F\cX]+)<(.+)>$/i;
const splitNameAddress = /^([^\x00-\x1F\x7F-\x9F\cX]+)</i;
const emailUserPart = /^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i;
const gmailUserPart = /^[a-z\d]+$/;
const quotedEmailUser = /^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i;
Expand All @@ -31,9 +31,7 @@ const defaultMaxEmailLength = 254;
* @param {String} display_name
*/
function validateDisplayName(display_name) {
const trim_quotes = display_name.match(/^"(.+)"$/i);
const display_name_without_quotes = trim_quotes ? trim_quotes[1] : display_name;

const display_name_without_quotes = display_name.replace(/^"(.+)"$/, '$1');
// display name with only spaces is not valid
if (!display_name_without_quotes.trim()) {
return false;
Expand All @@ -44,7 +42,7 @@ function validateDisplayName(display_name) {
if (contains_illegal) {
// if contains illegal characters,
// must to be enclosed in double-quotes, otherwise it's not a valid display name
if (!trim_quotes) {
if (display_name_without_quotes === display_name) {
return false;
}

Expand All @@ -67,8 +65,12 @@ export default function isEmail(str, options) {
if (options.require_display_name || options.allow_display_name) {
const display_email = str.match(splitNameAddress);
if (display_email) {
let display_name;
[, display_name, str] = display_email;
let display_name = display_email[1];

// Remove display name and angle brackets to get email address
// Can be done in the regex but will introduce a ReDOS (See #1597 for more info)
str = str.replace(display_name, '').replace(/(^<|>$)/g, '');

// sometimes need to trim the last space to get the display name
// because there may be a space between display name and email address
// eg. myname <address@gmail.com>
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;
});
}
Loading