Skip to content

Commit

Permalink
fix: fix A-z ranges (#1625)
Browse files Browse the repository at this point in the history
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].
  • Loading branch information
bmacnaughton authored Apr 17, 2021
1 parent 39830a9 commit b65ddc5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
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);
}
5 changes: 3 additions & 2 deletions src/lib/isISO31661Alpha2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import assertString from './util/assertString';
import includes from './util/includes';

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

export default function isISO31661Alpha2(str) {
assertString(str);
return includes(validISO31661Alpha2CountriesCodes, str.toUpperCase());
return validISO31661Alpha2CountriesCodes.indexOf(str.toUpperCase()) >= 0;
}

export const CountryCodes = validISO31661Alpha2CountriesCodes;
2 changes: 1 addition & 1 deletion src/lib/isLocale.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assertString from './util/assertString';

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

export default function isLocale(str) {
assertString(str);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/isPostalCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const patterns = {
HT: /^HT\d{4}$/,
HU: fourDigit,
ID: fiveDigit,
IE: /^(?!.*(?:o))[A-z]\d[\dw]\s\w{4}$/i,
IE: /^(?!.*(?:o))[A-Za-z]\d[\dw]\s\w{4}$/i,
IL: /^(\d{5}|\d{7})$/,
IN: /^((?!10|29|35|54|55|65|66|86|87|88|89)[1-9][0-9]{5})$/,
IR: /\b(?!(\d)\1{3})[13-9]{4}[1346-9][013-9]{5}\b/,
Expand Down

0 comments on commit b65ddc5

Please sign in to comment.