Skip to content

Commit

Permalink
Fix: Hexadecimal validation in v10 validator
Browse files Browse the repository at this point in the history
  • Loading branch information
V-R-Dighe committed Aug 19, 2022
1 parent 9e2ea40 commit 5405fa3
Show file tree
Hide file tree
Showing 17 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion regexes.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const (
alphaUnicodeNumericRegexString = "^[\\p{L}\\p{N}]+$"
numericRegexString = "^[-+]?[0-9]+(?:\\.[0-9]+)?$"
numberRegexString = "^[0-9]+$"
hexadecimalRegexString = "^(0[xX])?[0-9a-fA-F]+$"
hexadecimalRegexString = "^$|(^(0[xX])?[0-9a-fA-F]+$)"
hexColorRegexString = "^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$"
rgbRegexString = "^rgb\\(\\s*(?:(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])|(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%)\\s*\\)$"
rgbaRegexString = "^rgba\\(\\s*(?:(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])|(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%)\\s*,\\s*(?:(?:0.[1-9]*)|[01])\\s*\\)$"
Expand Down
1 change: 1 addition & 0 deletions translations/ar/ar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ func TestTranslations(t *testing.T) {
test.UniqueSlice = []string{"1234", "1234"}
test.UniqueMap = map[string]string{"key1": "1234", "key2": "1234"}
test.Datetime = "2008-Feb-01"
test.HexadecimalString = "xyz"

err = validate.Struct(test)
NotEqual(t, err, nil)
Expand Down
1 change: 1 addition & 0 deletions translations/en/en_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ func TestTranslations(t *testing.T) {
test.UniqueMap = map[string]string{"key1": "1234", "key2": "1234"}
test.Datetime = "2008-Feb-01"
test.BooleanString = "A"
test.HexadecimalString = "xyz"

test.Inner.RequiredIf = "abcd"

Expand Down
1 change: 1 addition & 0 deletions translations/es/es_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ func TestTranslations(t *testing.T) {

test.UniqueSlice = []string{"1234", "1234"}
test.UniqueMap = map[string]string{"key1": "1234", "key2": "1234"}
test.HexadecimalString = "xyz"

err = validate.Struct(test)
NotEqual(t, err, nil)
Expand Down
1 change: 1 addition & 0 deletions translations/fa/fa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ func TestTranslations(t *testing.T) {
test.UniqueSlice = []string{"1234", "1234"}
test.UniqueMap = map[string]string{"key1": "1234", "key2": "1234"}
test.Datetime = "2008-Feb-01"
test.HexadecimalString = "xyz"

err = validate.Struct(test)
NotEqual(t, err, nil)
Expand Down
1 change: 1 addition & 0 deletions translations/fr/fr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ func TestTranslations(t *testing.T) {
s := "toolong"
test.StrPtrMaxLen = &s
test.StrPtrLen = &s
test.HexadecimalString = "xyz"

err = validate.Struct(test)
NotEqual(t, err, nil)
Expand Down
1 change: 1 addition & 0 deletions translations/id/id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ func TestTranslations(t *testing.T) {
s := "toolong"
test.StrPtrMaxLen = &s
test.StrPtrLen = &s
test.HexadecimalString = "xyz"

err = validate.Struct(test)
NotEqual(t, err, nil)
Expand Down
1 change: 1 addition & 0 deletions translations/it/it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ func TestTranslations(t *testing.T) {
test.UniqueSlice = []string{"1234", "1234"}
test.UniqueMap = map[string]string{"key1": "1234", "key2": "1234"}
test.Datetime = "2008-Feb-01"
test.HexadecimalString = "xyz"

err = validate.Struct(test)
NotEqual(t, err, nil)
Expand Down
1 change: 1 addition & 0 deletions translations/ja/ja_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ func TestTranslations(t *testing.T) {
s := "toolong"
test.StrPtrMaxLen = &s
test.StrPtrLen = &s
test.HexadecimalString = "xyz"

err = validate.Struct(test)
NotEqual(t, err, nil)
Expand Down
1 change: 1 addition & 0 deletions translations/nl/nl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ func TestTranslations(t *testing.T) {
s := "toolong"
test.StrPtrMaxLen = &s
test.StrPtrLen = &s
test.HexadecimalString = "xyz"

err = validate.Struct(test)
NotEqual(t, err, nil)
Expand Down
1 change: 1 addition & 0 deletions translations/pt/pt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ func TestTranslations(t *testing.T) {
test.UniqueSlice = []string{"1234", "1234"}
test.UniqueMap = map[string]string{"key1": "1234", "key2": "1234"}
test.Datetime = "2008-Feb-01"
test.HexadecimalString = "xyz"

err = validate.Struct(test)
NotEqual(t, err, nil)
Expand Down
1 change: 1 addition & 0 deletions translations/pt_BR/pt_BR_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ func TestTranslations(t *testing.T) {
s := "toolong"
test.StrPtrMaxLen = &s
test.StrPtrLen = &s
test.HexadecimalString = "xyz"

err = validate.Struct(test)
NotEqual(t, err, nil)
Expand Down
1 change: 1 addition & 0 deletions translations/ru/ru_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ func TestTranslations(t *testing.T) {

test.UniqueSlice = []string{"1234", "1234"}
test.UniqueMap = map[string]string{"key1": "1234", "key2": "1234"}
test.HexadecimalString = "xyz"

err = validate.Struct(test)
NotEqual(t, err, nil)
Expand Down
1 change: 1 addition & 0 deletions translations/tr/tr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ func TestTranslations(t *testing.T) {

test.UniqueSlice = []string{"1234", "1234"}
test.UniqueMap = map[string]string{"key1": "1234", "key2": "1234"}
test.HexadecimalString = "xyz"

err = validate.Struct(test)
NotEqual(t, err, nil)
Expand Down
1 change: 1 addition & 0 deletions translations/vi/vi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ func TestTranslations(t *testing.T) {
test.UniqueSlice = []string{"1234", "1234"}
test.UniqueMap = map[string]string{"key1": "1234", "key2": "1234"}
test.Datetime = "2008-Feb-01"
test.HexadecimalString = "xyz"

err = validate.Struct(test)
NotEqual(t, err, nil)
Expand Down
1 change: 1 addition & 0 deletions translations/zh/zh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ func TestTranslations(t *testing.T) {
test.UppercaseString = "abcdefg"

test.Datetime = "20060102"
test.HexadecimalString = "xyz"

err = validate.Struct(test)
NotEqual(t, err, nil)
Expand Down
1 change: 1 addition & 0 deletions translations/zh_tw/zh_tw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ func TestTranslations(t *testing.T) {
test.StrPtrLen = &s

test.Datetime = "2008-Feb-01"
test.HexadecimalString = "xyz"

err = validate.Struct(test)
NotEqual(t, err, nil)
Expand Down

0 comments on commit 5405fa3

Please sign in to comment.