Skip to content

Commit

Permalink
conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
szabolcstarnai committed Feb 17, 2022
1 parent 10f5659 commit 76403fe
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 4 deletions.
11 changes: 11 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Security Policy

## Supported Versions

In the case of a confirmed security issue, only the current version of validator is guaranteed to be patched.

## Reporting a Vulnerability

**Please don't disclose security-related issues publicly.**

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.
2 changes: 2 additions & 0 deletions src/lib/isLicensePlate.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const validators = {
/^[A-Z]{2}[- ]?((\d{3}[- ]?(([A-Z]{2})|T))|(R[- ]?\d{3}))$/.test(str),
'pt-BR': str =>
/^[A-Z]{3}[ -]?[0-9][A-Z][0-9]{2}|[A-Z]{3}[ -]?[0-9]{4}$/.test(str),
'sv-SE': str =>
/^[A-HJ-PR-UW-Z]{3} ?[\d]{2}[A-HJ-PR-UW-Z1-9]$|(^[A-ZÅÄÖ ]{2,7}$)/.test(str.trim()),
};

export default function isLicensePlate(str, locale) {
Expand Down
38 changes: 34 additions & 4 deletions src/lib/isTaxID.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,36 @@ function bgBgCheck(tin) {
return checksum === digits[9];
}

/**
* Check if an input is a valid Canadian SIN (Social Insurance Number)
*
* The Social Insurance Number (SIN) is a 9 digit number that
* you need to work in Canada or to have access to government programs and benefits.
*
* https://en.wikipedia.org/wiki/Social_Insurance_Number
* https://www.canada.ca/en/employment-social-development/services/sin.html
* https://www.codercrunch.com/challenge/819302488/sin-validator
*
* @param {string} input
* @return {boolean}
*/
function isCanadianSIN(input) {
const digitsArray = input.split('');
const even = digitsArray
.filter((_, idx) => idx % 2)
.map(i => Number(i) * 2)
.join('')
.split('');

const total = digitsArray
.filter((_, idx) => !(idx % 2))
.concat(even)
.map(i => Number(i))
.reduce((acc, cur) => acc + cur);

return (total % 10 === 0);
}

/*
* cs-CZ validation function
* (Rodné číslo (RČ), persons only)
Expand Down Expand Up @@ -1096,14 +1126,14 @@ function svSeCheck(tin) {
* uppercase and lowercase letters are acceptable.
*/
const taxIdFormat = {

'bg-BG': /^\d{10}$/,
'cs-CZ': /^\d{6}\/{0,1}\d{3,4}$/,
'de-AT': /^\d{9}$/,
'de-DE': /^[1-9]\d{10}$/,
'dk-DK': /^\d{6}-{0,1}\d{4}$/,
'el-CY': /^[09]\d{7}[A-Z]$/,
'el-GR': /^([0-4]|[7-9])\d{8}$/,
'en-CA': /^\d{9}$/,
'en-GB': /^\d{10}$|^(?!GB|NK|TN|ZZ)(?![DFIQUV])[A-Z](?![DFIQUVO])[A-Z]\d{6}[ABCD ]$/i,
'en-IE': /^\d{7}[A-W][A-IW]{0,1}$/i,
'en-US': /^\d{2}[- ]{0,1}\d{7}$/,
Expand All @@ -1126,23 +1156,23 @@ const taxIdFormat = {
'sk-SK': /^\d{6}\/{0,1}\d{3,4}$/,
'sl-SI': /^[1-9]\d{7}$/,
'sv-SE': /^(\d{6}[-+]{0,1}\d{4}|(18|19|20)\d{6}[-+]{0,1}\d{4})$/,

};
// taxIdFormat locale aliases
taxIdFormat['lb-LU'] = taxIdFormat['fr-LU'];
taxIdFormat['lt-LT'] = taxIdFormat['et-EE'];
taxIdFormat['nl-BE'] = taxIdFormat['fr-BE'];
taxIdFormat['fr-CA'] = taxIdFormat['en-CA'];

// Algorithmic tax id check functions for various locales
const taxIdCheck = {

'bg-BG': bgBgCheck,
'cs-CZ': csCzCheck,
'de-AT': deAtCheck,
'de-DE': deDeCheck,
'dk-DK': dkDkCheck,
'el-CY': elCyCheck,
'el-GR': elGrCheck,
'en-CA': isCanadianSIN,
'en-IE': enIeCheck,
'en-US': enUsCheck,
'es-ES': esEsCheck,
Expand All @@ -1164,12 +1194,12 @@ const taxIdCheck = {
'sk-SK': skSkCheck,
'sl-SI': slSiCheck,
'sv-SE': svSeCheck,

};
// taxIdCheck locale aliases
taxIdCheck['lb-LU'] = taxIdCheck['fr-LU'];
taxIdCheck['lt-LT'] = taxIdCheck['et-EE'];
taxIdCheck['nl-BE'] = taxIdCheck['fr-BE'];
taxIdCheck['fr-CA'] = taxIdCheck['en-CA'];

// Regexes for locales where characters should be omitted before checking format
const allsymbols = /[-\\\/!@#$%\^&\*\(\)\+\=\[\]]+/g;
Expand Down
97 changes: 97 additions & 0 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -10312,6 +10312,23 @@ describe('Validators', () => {
'A1A 1A1',
'X0A-0H0',
'V5K 0A1',
'A1C 3S4',
'A1C3S4',
'a1c 3s4',
'V9A 7N2',
'B3K 5X5',
'K8N 5W6',
'K1A 0B1',
'B1Z 0B9',
],
invalid: [
' ',
'invalid value',
'a1a1a',
'A1A 1A1',
'K1A 0D1',
'W1A 0B1',
'Z1A 0B1',
],
},
{
Expand Down Expand Up @@ -10517,6 +10534,8 @@ describe('Validators', () => {
'78-399',
'39-490',
'38-483',
'05-800',
'54-060',
],
},
{
Expand Down Expand Up @@ -10575,6 +10594,9 @@ describe('Validators', () => {
'65000',
'65080',
'01000',
'51901',
'51909',
'49125',
],
},
{
Expand Down Expand Up @@ -10950,6 +10972,43 @@ describe('Validators', () => {
'658426713',
'558426713'],
});
test({
validator: 'isTaxID',
args: ['en-CA'],
valid: [
'000000000',
'521719666',
'469317481',
'120217450',
'480534858',
'325268597',
'336475660',
'744797853',
'130692544',
'046454286',
],
invalid: [
' ',
'any value',
'012345678',
'111111111',
'999999999',
'657449110',
'74 47 978 53',
'744 797 853',
'744-797-853',
'981062432',
'267500713',
'2675o0713',
'70597312',
'7058973122',
'069437151',
'046454281',
'146452286',
'30x92544',
'30692544',
],
});
test({
validator: 'isTaxID',
args: ['en-GB'],
Expand Down Expand Up @@ -11837,6 +11896,44 @@ describe('Validators', () => {
'FS AB 1234 A',
],
});
test({
validator: 'isLicensePlate',
args: ['sv-SE'],
valid: [
'ABC 123',
'ABC 12A',
'ABC123',
'ABC12A',
'A WORD',
'WORD',
'ÅSNA',
'EN VARG',
'CERISE',
'AA',
'ABCDEFG',
'ÅÄÖ',
'ÅÄÖ ÅÄÖ',
],
invalid: [
'',
' ',
'IQV 123',
'IQV123',
'ABI 12Q',
'ÅÄÖ 123',
'ÅÄÖ 12A',
'AB1 A23',
'AB1 12A',
'lower',
'abc 123',
'abc 12A',
'abc 12a',
'AbC 12a',
'WORDLONGERTHANSEVENCHARACTERS',
'A',
'ABC-123',
],
});
});
it('should validate VAT numbers', () => {
test({
Expand Down

0 comments on commit 76403fe

Please sign in to comment.