Fixed NotBlank validator to cover all whitespace characters (#997)

master
Aleksander Dejewski 2 years ago committed by GitHub
parent f6f934c4e9
commit c6f8637983
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      non-standard/validators/notblank.go
  2. 4
      non-standard/validators/notblank_test.go

@ -14,7 +14,7 @@ func NotBlank(fl validator.FieldLevel) bool {
switch field.Kind() { switch field.Kind() {
case reflect.String: 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: case reflect.Chan, reflect.Map, reflect.Slice, reflect.Array:
return field.Len() > 0 return field.Len() > 0
case reflect.Ptr, reflect.Interface, reflect.Func: case reflect.Ptr, reflect.Interface, reflect.Func:

@ -3,8 +3,8 @@ package validators
import ( import (
"testing" "testing"
"github.com/go-playground/validator/v10"
"github.com/go-playground/assert/v2" "github.com/go-playground/assert/v2"
"github.com/go-playground/validator/v10"
) )
type test struct { type test struct {
@ -24,7 +24,7 @@ func TestNotBlank(t *testing.T) {
// Errors // Errors
var x *int var x *int
invalid := test{ invalid := test{
String: " ", String: " \x1c\x1d\x1e\x1f\r\n",
Array: []int{}, Array: []int{},
Pointer: x, Pointer: x,
Number: 0, Number: 0,

Loading…
Cancel
Save