Skip to content

Commit a74c100

Browse files
committed
fix: revert to old validation regex and add more test cases
1 parent 664102b commit a74c100

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

regexes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const (
6868
hTMLRegexString = `<[/]?([a-zA-Z]+).*?>`
6969
jWTRegexString = "^[A-Za-z0-9-_]+\\.[A-Za-z0-9-_]+\\.[A-Za-z0-9-_]*$"
7070
splitParamsRegexString = `'[^']*'|\S+`
71-
bicRegexString = `^(?:[A-Z]{4}|[A-Z][0-9]{3})[A-Z]{2}[A-Z0-9]{2}(?:[A-Z0-9]{3})?$`
71+
bicRegexString = `^[A-Z0-9]{4}[A-Z]{2}[A-Z0-9]{2}(?:[A-Z0-9]{3})?$`
7272
semverRegexString = `^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$` // numbered capture groups https://semver.org/
7373
dnsRegexStringRFC1035Label = "^[a-z]([-a-z0-9]*[a-z0-9])?$"
7474
cveRegexString = `^CVE-(1999|2\d{3})-(0[^0]\d{2}|0\d[^0]\d{1}|0\d{2}[^0]|[1-9]{1}\d{3,})$` // CVE Format Id https://cve.mitre.org/cve/identifiers/syntaxchange.html

validator_test.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13214,11 +13214,44 @@ func TestBicIsoFormatValidation(t *testing.T) {
1321413214
{"SBICKEN1YYP", "bic", true},
1321513215
{"E097AEXX", "bic", true}, // valid under https://www.iso.org/standard/84108.html
1321613216
{"SBIC23NXXX", "bic", false},
13217-
{"S23CKENXXXX", "bic", false},
13217+
{"S23CKENXXXX", "bic", true},
1321813218
{"SBICKENXX", "bic", false},
1321913219
{"SBICKENXX9", "bic", false},
1322013220
{"SBICKEN13458", "bic", false},
1322113221
{"SBICKEN", "bic", false},
13222+
{"DEUTDEFF", "bic", true}, // 8-char classic (Germany)
13223+
{"DEUTDEFF500", "bic", true}, // 11-char with numeric branch
13224+
{"A1B2US33", "bic", true}, // digits allowed in 4!c (bank code)
13225+
{"1234US33", "bic", true}, // all digits in 4!c (2022)
13226+
{"ZZZ1USAA", "bic", true}, // mixed alnum bank + alnum location
13227+
{"AB12AE00", "bic", true}, // UAE 8-char
13228+
{"AB12AE009Z9", "bic", true}, // UAE 11-char with mixed branch
13229+
{"WG11US335AB", "bic", true}, // example-style with digits in branch
13230+
{"BNPAFRPP", "bic", true}, // France (BNP Paribas style)
13231+
{"BOFAUS3NXXX", "bic", true}, // US with default XXX branch
13232+
{"HSBCHKHHXXX", "bic", true}, // Hong Kong, default branch
13233+
{"NEDSZAJJ", "bic", true}, // South Africa 8-char
13234+
{"BARCGB22", "bic", true}, // GB 8-char
13235+
{"BARCGB22XXX", "bic", true}, // GB 11-char with XXX branch
13236+
{"0000GB00", "bic", true}, // 4!c all digits + 2!c all digits (allowed)
13237+
{"A1B2GB00XXX", "bic", true}, // valid 11-char with numeric location and XXX
13238+
{"TATRAEBX", "bic", true}, // UAE 8-char
13239+
{"TATRSABX", "bic", true}, // Saudi 8-char
13240+
{"TATREGBX", "bic", true}, // Egypt 8-char
13241+
{"TATRBHBX", "bic", true}, // Bahrain 8-char
13242+
13243+
{"DEUTDEFFF", "bic", false}, // 9-char (invalid length)
13244+
{"DEUTDEFF5", "bic", false}, // 9-char (invalid length)
13245+
{"DEUTDE", "bic", false}, // 6-char (invalid length)
13246+
{"DEUTDEFF50", "bic", false}, // 10-char (invalid length)
13247+
{"DEUTDEFF5000", "bic", false}, // 12-char (invalid length)
13248+
{"deUTDEFF", "bic", false}, // lowercase not allowed
13249+
{"DEUTDEfF", "bic", false}, // lowercase in location
13250+
{"DEU@DEFF", "bic", false}, // special char in bank
13251+
{"ABCD12FF", "bic", false}, // digits in 2!a country (invalid)
13252+
{"ABCDDE1-", "bic", false}, // hyphen in location
13253+
{"ABCDDE1_", "bic", false}, // underscore in location
13254+
{"ABCDDE١٢", "bic", false}, // non-ASCII digits in location
1322213255
}
1322313256

1322413257
validate := New()

0 commit comments

Comments
 (0)