Skip to content

Commit

Permalink
Fixed NotBlank validator to cover all whitespace characters (#997)
Browse files Browse the repository at this point in the history
  • Loading branch information
adejewski-msol authored Mar 19, 2023
1 parent f6f934c commit c6f8637
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion non-standard/validators/notblank.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func NotBlank(fl validator.FieldLevel) bool {

switch field.Kind() {
case reflect.String:
return len(strings.TrimSpace(field.String())) > 0
return len(strings.Trim(strings.TrimSpace(field.String()), "\x1c\x1d\x1e\x1f")) > 0
case reflect.Chan, reflect.Map, reflect.Slice, reflect.Array:
return field.Len() > 0
case reflect.Ptr, reflect.Interface, reflect.Func:
Expand Down
4 changes: 2 additions & 2 deletions non-standard/validators/notblank_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package validators
import (
"testing"

"github.com/go-playground/validator/v10"
"github.com/go-playground/assert/v2"
"github.com/go-playground/validator/v10"
)

type test struct {
Expand All @@ -24,7 +24,7 @@ func TestNotBlank(t *testing.T) {
// Errors
var x *int
invalid := test{
String: " ",
String: " \x1c\x1d\x1e\x1f\r\n",
Array: []int{},
Pointer: x,
Number: 0,
Expand Down

0 comments on commit c6f8637

Please sign in to comment.