Skip to content

Commit

Permalink
Fix: Remove bytes prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Sep 3, 2023
1 parent cd70469 commit 601180a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions internal/bcd/ast/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ type ValidatorConstraint interface {
type Validator[T ValidatorConstraint] func(T) error

var (
hexRegex = regexp.MustCompile("^[0-9a-fA-F]+$")
hexWithPrefixRegex = regexp.MustCompile("^(0x)?[0-9a-fA-F]+$")
hexRegex = regexp.MustCompile("^[0-9a-fA-F]+$")
)

// AddressValidator -
Expand Down Expand Up @@ -125,7 +124,7 @@ func BytesValidator(value string) error {
if len(value)%2 > 0 {
return errors.Wrapf(ErrValidation, "invalid bytes in hex length '%s'", value)
}
if value != "" && !hexWithPrefixRegex.MatchString(value) {
if value != "" && !hexRegex.MatchString(value) {
return errors.Wrapf(ErrValidation, "bytes '%s' should be hexademical without prefixes", value)
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion internal/bcd/ast/validators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func TestBytesValidator(t *testing.T) {
}, {
name: "test 3",
value: "0x030ed412d33412ab4b71df0aaba07df7ddd2a44eb55c87bf81868ba09a358bc0e0",
wantErr: false,
wantErr: true,
}, {
name: "test 4",
value: "",
Expand Down

0 comments on commit 601180a

Please sign in to comment.