Skip to content

Commit 67d3da0

Browse files
authored
Merge branch 'go-playground:master' into master
2 parents fd2447b + 80b6d11 commit 67d3da0

File tree

8 files changed

+62
-19
lines changed

8 files changed

+62
-19
lines changed

.github/workflows/go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: ${{ matrix.os }}
1414
steps:
1515
- name: Checkout code
16-
uses: actions/checkout@v5
16+
uses: actions/checkout@v6
1717

1818
- name: Install Go
1919
uses: actions/setup-go@v6

.github/workflows/workflow.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: ${{ matrix.os }}
1414
steps:
1515
- name: Checkout code
16-
uses: actions/checkout@v5
16+
uses: actions/checkout@v6
1717

1818
- name: Install Go
1919
uses: actions/setup-go@v6
@@ -33,7 +33,7 @@ jobs:
3333
name: lint
3434
runs-on: ubuntu-latest
3535
steps:
36-
- uses: actions/checkout@v5
36+
- uses: actions/checkout@v6
3737
- uses: actions/setup-go@v6
3838
with:
3939
go-version: 1.24.x

baked_in.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,12 +535,20 @@ func hasMultiByteCharacter(fl FieldLevel) bool {
535535

536536
// isPrintableASCII is the validation function for validating if the field's value is a valid printable ASCII character.
537537
func isPrintableASCII(fl FieldLevel) bool {
538-
return printableASCIIRegex().MatchString(fl.Field().String())
538+
field := fl.Field()
539+
if field.Kind() == reflect.String {
540+
return printableASCIIRegex().MatchString(field.String())
541+
}
542+
return false
539543
}
540544

541545
// isASCII is the validation function for validating if the field's value is a valid ASCII character.
542546
func isASCII(fl FieldLevel) bool {
543-
return aSCIIRegex().MatchString(fl.Field().String())
547+
field := fl.Field()
548+
if field.Kind() == reflect.String {
549+
return aSCIIRegex().MatchString(field.String())
550+
}
551+
return false
544552
}
545553

546554
// isUUID5 is the validation function for validating if the field's value is a valid v5 UUID.

currency_codes.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var iso4217 = map[string]struct{}{
2727
"OMR": {}, "PKR": {}, "PAB": {}, "PGK": {}, "PYG": {},
2828
"PEN": {}, "PHP": {}, "PLN": {}, "QAR": {}, "RON": {},
2929
"RUB": {}, "RWF": {}, "SHP": {}, "WST": {}, "STN": {},
30-
"SAR": {}, "RSD": {}, "SCR": {}, "SLL": {}, "SGD": {},
30+
"SAR": {}, "RSD": {}, "SCR": {}, "SLE": {}, "SGD": {},
3131
"XSU": {}, "SBD": {}, "SOS": {}, "SSP": {}, "LKR": {},
3232
"SDG": {}, "SRD": {}, "SEK": {}, "CHE": {}, "CHW": {},
3333
"SYP": {}, "TWD": {}, "TJS": {}, "TZS": {}, "THB": {},
@@ -59,7 +59,7 @@ var iso4217_numeric = map[int]struct{}{
5959
532: {}, 533: {}, 548: {}, 554: {}, 558: {},
6060
566: {}, 578: {}, 586: {}, 590: {}, 598: {},
6161
600: {}, 604: {}, 608: {}, 634: {}, 643: {},
62-
646: {}, 654: {}, 682: {}, 690: {}, 694: {},
62+
646: {}, 654: {}, 682: {}, 690: {}, 925: {},
6363
702: {}, 704: {}, 706: {}, 710: {}, 728: {},
6464
748: {}, 752: {}, 756: {}, 760: {}, 764: {},
6565
776: {}, 780: {}, 784: {}, 788: {}, 800: {},

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ require (
88
github.com/go-playground/locales v0.14.1
99
github.com/go-playground/universal-translator v0.18.1
1010
github.com/leodido/go-urn v1.4.0
11-
golang.org/x/crypto v0.43.0
12-
golang.org/x/text v0.30.0
11+
golang.org/x/crypto v0.45.0
12+
golang.org/x/text v0.31.0
1313
)
1414

15-
require golang.org/x/sys v0.37.0 // indirect
15+
require golang.org/x/sys v0.38.0 // indirect

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
1414
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
1515
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
1616
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
17-
golang.org/x/crypto v0.43.0 h1:dduJYIi3A3KOfdGOHX8AVZ/jGiyPa3IbBozJ5kNuE04=
18-
golang.org/x/crypto v0.43.0/go.mod h1:BFbav4mRNlXJL4wNeejLpWxB7wMbc79PdRGhWKncxR0=
19-
golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ=
20-
golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
21-
golang.org/x/text v0.30.0 h1:yznKA/E9zq54KzlzBEAWn1NXSQ8DIp/NYMy88xJjl4k=
22-
golang.org/x/text v0.30.0/go.mod h1:yDdHFIX9t+tORqspjENWgzaCVXgk0yYnYuSZ8UzzBVM=
17+
golang.org/x/crypto v0.45.0 h1:jMBrvKuj23MTlT0bQEOBcAE0mjg8mK9RXFhRH6nyF3Q=
18+
golang.org/x/crypto v0.45.0/go.mod h1:XTGrrkGJve7CYK7J8PEww4aY7gM3qMCElcJQ8n8JdX4=
19+
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
20+
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
21+
golang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM=
22+
golang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM=
2323
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
2424
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

regexes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const (
2121
hslRegexString = "^hsl\\(\\s*(?:0|[1-9]\\d?|[12]\\d\\d|3[0-5]\\d|360)\\s*,\\s*(?:(?:0|[1-9]\\d?|100)%)\\s*,\\s*(?:(?:0|[1-9]\\d?|100)%)\\s*\\)$"
2222
hslaRegexString = "^hsla\\(\\s*(?:0|[1-9]\\d?|[12]\\d\\d|3[0-5]\\d|360)\\s*,\\s*(?:(?:0|[1-9]\\d?|100)%)\\s*,\\s*(?:(?:0|[1-9]\\d?|100)%)\\s*,\\s*(?:(?:0.[1-9]*)|[01])\\s*\\)$"
2323
emailRegexString = "^(?:(?:(?:(?:[a-zA-Z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])+(?:\\.([a-zA-Z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])+)*)|(?:(?:\\x22)(?:(?:(?:(?:\\x20|\\x09)*(?:\\x0d\\x0a))?(?:\\x20|\\x09)+)?(?:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]|\\x21|[\\x23-\\x5b]|[\\x5d-\\x7e]|[\\x{00A0}-\\x{D7F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})*(?:[A-Za-z0-9+\\/]{2}==|[A-Za-z0-9+\\/]{3}=|[A-Za-z0-9+\\/]{4})$"
2727
base64URLRegexString = "^(?:[A-Za-z0-9-_]{4})*(?:[A-Za-z0-9-_]{2}==|[A-Za-z0-9-_]{3}=|[A-Za-z0-9-_]{4})$"

validator_test.go

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3904,7 +3904,7 @@ func TestMultibyteValidation(t *testing.T) {
39043904

39053905
func TestPrintableASCIIValidation(t *testing.T) {
39063906
tests := []struct {
3907-
param string
3907+
param interface{}
39083908
expected bool
39093909
}{
39103910
{"", true},
@@ -3918,6 +3918,8 @@ func TestPrintableASCIIValidation(t *testing.T) {
39183918
{"1234abcDEF", true},
39193919
{"newline\n", false},
39203920
{"\x19test\x7F", false},
3921+
{[]int{3000}, false},
3922+
{1, false},
39213923
}
39223924

39233925
validate := New()
@@ -3944,7 +3946,7 @@ func TestPrintableASCIIValidation(t *testing.T) {
39443946

39453947
func TestASCIIValidation(t *testing.T) {
39463948
tests := []struct {
3947-
param string
3949+
param interface{}
39483950
expected bool
39493951
}{
39503952
{"", true},
@@ -3957,6 +3959,8 @@ func TestASCIIValidation(t *testing.T) {
39573959
{"[email protected]", true},
39583960
{"1234abcDEF", true},
39593961
{"", true},
3962+
{[]int{3000}, false},
3963+
{1, false},
39603964
}
39613965

39623966
validate := New()
@@ -8734,6 +8738,33 @@ func TestRgb(t *testing.T) {
87348738
AssertError(t, errs, "", "", "", "", "rgb")
87358739
}
87368740

8741+
func TestE164(t *testing.T) {
8742+
validate := New()
8743+
8744+
s := "+12025550123"
8745+
errs := validate.Var(s, "e164")
8746+
Equal(t, errs, nil)
8747+
8748+
s = "+447911123456"
8749+
errs = validate.Var(s, "e164")
8750+
Equal(t, errs, nil)
8751+
8752+
s = "0123456789" // invalid: starts with 0
8753+
errs = validate.Var(s, "e164")
8754+
NotEqual(t, errs, nil)
8755+
AssertError(t, errs, "", "", "", "", "e164")
8756+
8757+
s = "++12025550123" // invalid: double +
8758+
errs = validate.Var(s, "e164")
8759+
NotEqual(t, errs, nil)
8760+
AssertError(t, errs, "", "", "", "", "e164")
8761+
8762+
s = "+1 202-555-0123" // invalid: contains spaces or dashes
8763+
errs = validate.Var(s, "e164")
8764+
NotEqual(t, errs, nil)
8765+
AssertError(t, errs, "", "", "", "", "e164")
8766+
}
8767+
87378768
func TestEmail(t *testing.T) {
87388769
validate := New()
87398770

@@ -13098,6 +13129,8 @@ func TestIsIso4217Validation(t *testing.T) {
1309813129
{"TRY", true},
1309913130
{"EUR", true},
1310013131
{"USA", false},
13132+
{"SLE", true},
13133+
{"SLL", false},
1310113134
}
1310213135

1310313136
validate := New()
@@ -13125,6 +13158,8 @@ func TestIsIso4217NumericValidation(t *testing.T) {
1312513158
{8, true},
1312613159
{12, true},
1312713160
{13, false},
13161+
{925, true},
13162+
{694, false},
1312813163
}
1312913164

1313013165
validate := New()

0 commit comments

Comments
 (0)