Skip to content

Commit b65ddc5

Browse files
authored
fix: fix A-z ranges (#1625)
A number of files contain ranges of [A-z] which allows the characters [\]^_\ and the back-tick character. Those have been replaced by [A-Za-z].
1 parent 39830a9 commit b65ddc5

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

src/lib/isBIC.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
import assertString from './util/assertString';
2+
import { CountryCodes } from './isISO31661Alpha2';
23

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

57
export default function isBIC(str) {
68
assertString(str);
9+
10+
// toUpperCase() should be removed when a new major version goes out that changes
11+
// the regex to [A-Z] (per the spec).
12+
if (CountryCodes.indexOf(str.slice(4, 6).toUpperCase()) < 0) {
13+
return false;
14+
}
15+
716
return isBICReg.test(str);
817
}

src/lib/isISO31661Alpha2.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import assertString from './util/assertString';
2-
import includes from './util/includes';
32

43
// from https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
54
const validISO31661Alpha2CountriesCodes = [
@@ -32,5 +31,7 @@ const validISO31661Alpha2CountriesCodes = [
3231

3332
export default function isISO31661Alpha2(str) {
3433
assertString(str);
35-
return includes(validISO31661Alpha2CountriesCodes, str.toUpperCase());
34+
return validISO31661Alpha2CountriesCodes.indexOf(str.toUpperCase()) >= 0;
3635
}
36+
37+
export const CountryCodes = validISO31661Alpha2CountriesCodes;

src/lib/isLocale.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import assertString from './util/assertString';
22

3-
const localeReg = /^[A-z]{2,4}([_-]([A-z]{4}|[\d]{3}))?([_-]([A-z]{2}|[\d]{3}))?$/;
3+
const localeReg = /^[A-Za-z]{2,4}([_-]([A-Za-z]{4}|[\d]{3}))?([_-]([A-Za-z]{2}|[\d]{3}))?$/;
44

55
export default function isLocale(str) {
66
assertString(str);

src/lib/isPostalCode.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const patterns = {
3333
HT: /^HT\d{4}$/,
3434
HU: fourDigit,
3535
ID: fiveDigit,
36-
IE: /^(?!.*(?:o))[A-z]\d[\dw]\s\w{4}$/i,
36+
IE: /^(?!.*(?:o))[A-Za-z]\d[\dw]\s\w{4}$/i,
3737
IL: /^(\d{5}|\d{7})$/,
3838
IN: /^((?!10|29|35|54|55|65|66|86|87|88|89)[1-9][0-9]{5})$/,
3939
IR: /\b(?!(\d)\1{3})[13-9]{4}[1346-9][013-9]{5}\b/,

0 commit comments

Comments
 (0)