Skip to content

Commit afdbd68

Browse files
authored
Merge branch 'master' into feature/all-country-regex
2 parents fba9680 + c193fe5 commit afdbd68

24 files changed

+800
-77
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL"
13+
14+
on:
15+
push:
16+
branches: [ master ]
17+
pull_request:
18+
# The branches below must be a subset of the branches above
19+
branches: [ master ]
20+
schedule:
21+
- cron: '38 10 * * 4'
22+
23+
jobs:
24+
analyze:
25+
name: Analyze
26+
runs-on: ubuntu-latest
27+
permissions:
28+
actions: read
29+
contents: read
30+
security-events: write
31+
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
language: [ 'javascript' ]
36+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
37+
# Learn more about CodeQL language support at https://git.io/codeql-language-support
38+
39+
steps:
40+
- name: Checkout repository
41+
uses: actions/checkout@v2
42+
43+
# Initializes the CodeQL tools for scanning.
44+
- name: Initialize CodeQL
45+
uses: github/codeql-action/init@v1
46+
with:
47+
languages: ${{ matrix.language }}
48+
# If you wish to specify custom queries, you can do so here or in a config file.
49+
# By default, queries listed here will override any specified in a config file.
50+
# Prefix the list here with "+" to use these queries and those in the config file.
51+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
52+
53+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
54+
# If this step fails, then you should remove it and run the build manually (see below)
55+
- name: Autobuild
56+
uses: github/codeql-action/autobuild@v1
57+
58+
# ℹ️ Command-line programs to run using the OS shell.
59+
# 📚 https://git.io/JvXDl
60+
61+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
62+
# and modify them (or add more) to build your code if your project
63+
# uses a compiled language
64+
65+
#- run: |
66+
# make bootstrap
67+
# make release
68+
69+
- name: Perform CodeQL Analysis
70+
uses: github/codeql-action/analyze@v1

README.md

Lines changed: 21 additions & 10 deletions
Large diffs are not rendered by default.

SECURITY.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Security Policy
2+
3+
## Supported Versions
4+
5+
In the case of a confirmed security issue, only the current version of validator is guaranteed to be patched.
6+
7+
## Reporting a Vulnerability
8+
9+
**Please don't disclose security-related issues publicly.**
10+
11+
If you discover a vulnerability within validator, please use [huntr.dev disclosure form](https://huntr.dev/bounties/disclose/?target=https://github.com/validatorjs/validator.js). We will try to validate and respond to reports in a reasonable time. if the issue is confirmed, we will create a security advisory and a patch as soon as possible.

src/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ import isBefore from './lib/isBefore';
6969

7070
import isIn from './lib/isIn';
7171

72+
import isLuhnValid from './lib/isLuhnValid';
7273
import isCreditCard from './lib/isCreditCard';
7374
import isIdentityCard from './lib/isIdentityCard';
7475

@@ -86,6 +87,7 @@ import isCurrency from './lib/isCurrency';
8687

8788
import isBtcAddress from './lib/isBtcAddress';
8889

90+
import isISO6391 from './lib/isISO6391';
8991
import isISO8601 from './lib/isISO8601';
9092
import isRFC3339 from './lib/isRFC3339';
9193
import isISO31661Alpha2 from './lib/isISO31661Alpha2';
@@ -182,6 +184,7 @@ const validator = {
182184
isAfter,
183185
isBefore,
184186
isIn,
187+
isLuhnValid,
185188
isCreditCard,
186189
isIdentityCard,
187190
isEAN,
@@ -195,6 +198,7 @@ const validator = {
195198
isEthereumAddress,
196199
isCurrency,
197200
isBtcAddress,
201+
isISO6391,
198202
isISO8601,
199203
isRFC3339,
200204
isISO31661Alpha2,

src/lib/alpha.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export const alpha = {
3232
he: /^[א-ת]+$/,
3333
fa: /^['آاءأؤئبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهةی']+$/i,
3434
'hi-IN': /^[\u0900-\u0961]+[\u0972-\u097F]*$/i,
35+
'si-LK': /^[\u0D80-\u0DFF]+$/,
3536
};
3637

3738
export const alphanumeric = {
@@ -67,6 +68,7 @@ export const alphanumeric = {
6768
he: /^[0-9א-ת]+$/,
6869
fa: /^['0-9آاءأؤئبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهةی۱۲۳۴۵۶۷۸۹۰']+$/i,
6970
'hi-IN': /^[\u0900-\u0963]+[\u0966-\u097F]*$/i,
71+
'si-LK': /^[0-9\u0D80-\u0DFF]+$/,
7072
};
7173

7274
export const decimal = {
@@ -112,7 +114,7 @@ export const dotDecimal = ['ar-EG', 'ar-LB', 'ar-LY'];
112114
export const commaDecimal = [
113115
'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-ZM', 'es-ES', 'fr-CA', 'fr-FR',
114116
'id-ID', 'it-IT', 'ku-IQ', 'hi-IN', 'hu-HU', 'nb-NO', 'nn-NO', 'nl-NL', 'pl-PL', 'pt-PT',
115-
'ru-RU', 'sl-SI', 'sr-RS@latin', 'sr-RS', 'sv-SE', 'tr-TR', 'uk-UA', 'vi-VN',
117+
'ru-RU', 'si-LK', 'sl-SI', 'sr-RS@latin', 'sr-RS', 'sv-SE', 'tr-TR', 'uk-UA', 'vi-VN',
116118
];
117119

118120
for (let i = 0; i < dotDecimal.length; i++) {

src/lib/isBase32.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
import assertString from './util/assertString';
2+
import merge from './util/merge';
23

34
const base32 = /^[A-Z2-7]+=*$/;
5+
const crockfordBase32 = /^[A-HJKMNP-TV-Z0-9]+$/;
46

5-
export default function isBase32(str) {
7+
const defaultBase32Options = {
8+
crockford: false,
9+
};
10+
11+
export default function isBase32(str, options) {
612
assertString(str);
13+
options = merge(options, defaultBase32Options);
14+
15+
if (options.crockford) {
16+
return crockfordBase32.test(str);
17+
}
18+
719
const len = str.length;
820
if (len % 8 === 0 && base32.test(str)) {
921
return true;

src/lib/isCreditCard.js

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import assertString from './util/assertString';
2+
import isLuhnValid from './isLuhnValid';
23

34
/* eslint-disable max-len */
45
const creditCard = /^(?:4[0-9]{12}(?:[0-9]{3,6})?|5[1-5][0-9]{14}|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}|6(?:011|5[0-9][0-9])[0-9]{12,15}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11}|6[27][0-9]{14}|^(81[0-9]{14,17}))$/;
@@ -10,24 +11,5 @@ export default function isCreditCard(str) {
1011
if (!creditCard.test(sanitized)) {
1112
return false;
1213
}
13-
let sum = 0;
14-
let digit;
15-
let tmpNum;
16-
let shouldDouble;
17-
for (let i = sanitized.length - 1; i >= 0; i--) {
18-
digit = sanitized.substring(i, (i + 1));
19-
tmpNum = parseInt(digit, 10);
20-
if (shouldDouble) {
21-
tmpNum *= 2;
22-
if (tmpNum >= 10) {
23-
sum += ((tmpNum % 10) + 1);
24-
} else {
25-
sum += tmpNum;
26-
}
27-
} else {
28-
sum += tmpNum;
29-
}
30-
shouldDouble = !shouldDouble;
31-
}
32-
return !!((sum % 10) === 0 ? sanitized : false);
14+
return isLuhnValid(str);
3315
}

src/lib/isDataURI.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import assertString from './util/assertString';
22

3-
const validMediaType = /^[a-z]+\/[a-z0-9\-\+]+$/i;
3+
const validMediaType = /^[a-z]+\/[a-z0-9\-\+\.]+$/i;
44

55
const validAttribute = /^[a-z\-]+=[a-z0-9\-]+$/i;
66

@@ -14,10 +14,10 @@ export default function isDataURI(str) {
1414
}
1515
const attributes = data.shift().trim().split(';');
1616
const schemeAndMediaType = attributes.shift();
17-
if (schemeAndMediaType.substr(0, 5) !== 'data:') {
17+
if (schemeAndMediaType.slice(0, 5) !== 'data:') {
1818
return false;
1919
}
20-
const mediaType = schemeAndMediaType.substr(5);
20+
const mediaType = schemeAndMediaType.slice(5);
2121
if (mediaType !== '' && !validMediaType.test(mediaType)) {
2222
return false;
2323
}

src/lib/isEmail.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export default function isEmail(str, options) {
7777
// eg. myname <[email protected]>
7878
// the display name is `myname` instead of `myname `, so need to trim the last space
7979
if (display_name.endsWith(' ')) {
80-
display_name = display_name.substr(0, display_name.length - 1);
80+
display_name = display_name.slice(0, -1);
8181
}
8282

8383
if (!validateDisplayName(display_name)) {
@@ -144,7 +144,7 @@ export default function isEmail(str, options) {
144144
return false;
145145
}
146146

147-
let noBracketdomain = domain.substr(1, domain.length - 2);
147+
let noBracketdomain = domain.slice(1, -1);
148148

149149
if (noBracketdomain.length === 0 || !isIP(noBracketdomain)) {
150150
return false;

src/lib/isFQDN.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default function isFQDN(str, options) {
3232
return false;
3333
}
3434

35-
if (!/^([a-z\u00A1-\u00A8\u00AA-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{2,}|xn[a-z0-9-]{2,})$/i.test(tld)) {
35+
if (!options.allow_numeric_tld && !/^([a-z\u00A1-\u00A8\u00AA-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{2,}|xn[a-z0-9-]{2,})$/i.test(tld)) {
3636
return false;
3737
}
3838

0 commit comments

Comments
 (0)