Skip to content

Commit c6f8637

Browse files
Fixed NotBlank validator to cover all whitespace characters (#997)
1 parent f6f934c commit c6f8637

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

non-standard/validators/notblank.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func NotBlank(fl validator.FieldLevel) bool {
1414

1515
switch field.Kind() {
1616
case reflect.String:
17-
return len(strings.TrimSpace(field.String())) > 0
17+
return len(strings.Trim(strings.TrimSpace(field.String()), "\x1c\x1d\x1e\x1f")) > 0
1818
case reflect.Chan, reflect.Map, reflect.Slice, reflect.Array:
1919
return field.Len() > 0
2020
case reflect.Ptr, reflect.Interface, reflect.Func:

non-standard/validators/notblank_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package validators
33
import (
44
"testing"
55

6-
"github.com/go-playground/validator/v10"
76
"github.com/go-playground/assert/v2"
7+
"github.com/go-playground/validator/v10"
88
)
99

1010
type test struct {
@@ -24,7 +24,7 @@ func TestNotBlank(t *testing.T) {
2424
// Errors
2525
var x *int
2626
invalid := test{
27-
String: " ",
27+
String: " \x1c\x1d\x1e\x1f\r\n",
2828
Array: []int{},
2929
Pointer: x,
3030
Number: 0,

0 commit comments

Comments
 (0)