diff options
author | 2023-06-05 10:15:05 +0200 | |
---|---|---|
committer | 2023-06-05 10:15:05 +0200 | |
commit | b401bd1ccbce7fa547c75e9f0ae89e211112c1bb (patch) | |
tree | 08bf9ed438713e8c390ea60732e7dfc14b0d3191 /vendor/github.com/go-playground/validator/v10/baked_in.go | |
parent | [chore]: Bump github.com/minio/minio-go/v7 from 7.0.55 to 7.0.56 (#1869) (diff) | |
download | gotosocial-b401bd1ccbce7fa547c75e9f0ae89e211112c1bb.tar.xz |
[chore] update latest deps, ensure readme up to date (#1873)
* [chore] update latest deps, ensure readme up to date
* remove double entry
Diffstat (limited to 'vendor/github.com/go-playground/validator/v10/baked_in.go')
-rw-r--r-- | vendor/github.com/go-playground/validator/v10/baked_in.go | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/vendor/github.com/go-playground/validator/v10/baked_in.go b/vendor/github.com/go-playground/validator/v10/baked_in.go index 8e6b169cb..e676f1d16 100644 --- a/vendor/github.com/go-playground/validator/v10/baked_in.go +++ b/vendor/github.com/go-playground/validator/v10/baked_in.go @@ -1414,25 +1414,21 @@ func isURL(fl FieldLevel) bool { switch field.Kind() { case reflect.String: - var i int s := field.String() - // checks needed as of Go 1.6 because of change https://github.com/golang/go/commit/617c93ce740c3c3cc28cdd1a0d712be183d0b328#diff-6c2d018290e298803c0c9419d8739885L195 - // emulate browser and strip the '#' suffix prior to validation. see issue-#237 - if i = strings.Index(s, "#"); i > -1 { - s = s[:i] - } - if len(s) == 0 { return false } - url, err := url.ParseRequestURI(s) - + url, err := url.Parse(s) if err != nil || url.Scheme == "" { return false } + if url.Host == "" && url.Fragment == "" && url.Opaque == "" { + return false + } + return true } @@ -1450,7 +1446,13 @@ func isHttpURL(fl FieldLevel) bool { case reflect.String: s := strings.ToLower(field.String()) - return strings.HasPrefix(s, "http://") || strings.HasPrefix(s, "https://") + + url, err := url.Parse(s) + if err != nil || url.Host == "" { + return false + } + + return url.Scheme == "http" || url.Scheme == "https" } panic(fmt.Sprintf("Bad field type %T", field.Interface())) @@ -2568,9 +2570,17 @@ func isDirPath(fl FieldLevel) bool { func isJSON(fl FieldLevel) bool { field := fl.Field() - if field.Kind() == reflect.String { + switch field.Kind() { + case reflect.String: val := field.String() return json.Valid([]byte(val)) + case reflect.Slice: + fieldType := field.Type() + + if fieldType.ConvertibleTo(byteSliceType) { + b := field.Convert(byteSliceType).Interface().([]byte) + return json.Valid(b) + } } panic(fmt.Sprintf("Bad field type %T", field.Interface())) |