bump reva to lastest main
for https://github.com/opencloud-eu/reva/pull/372
This commit is contained in:
committed by
Ralf Haferkamp
parent
d080d7415e
commit
805bd4305e
+5
-2
@@ -106,8 +106,9 @@ validate := validator.New(validator.WithRequiredStructEnabled())
|
||||
| datauri | Data URL |
|
||||
| fqdn | Full Qualified Domain Name (FQDN) |
|
||||
| hostname | Hostname RFC 952 |
|
||||
| hostname_port | HostPort |
|
||||
| hostname_rfc1123 | Hostname RFC 1123 |
|
||||
| hostname_port | HostPort |
|
||||
| port | Port number |
|
||||
| ip | Internet Protocol Address IP |
|
||||
| ip4_addr | Internet Protocol Address IPv4 |
|
||||
| ip6_addr | Internet Protocol Address IPv6 |
|
||||
@@ -124,7 +125,8 @@ validate := validator.New(validator.WithRequiredStructEnabled())
|
||||
| unix_addr | Unix domain socket end point Address |
|
||||
| uri | URI String |
|
||||
| url | URL String |
|
||||
| http_url | HTTP URL String |
|
||||
| http_url | HTTP(s) URL String |
|
||||
| https_url | HTTPS-only URL String |
|
||||
| url_encoded | URL Encoded |
|
||||
| urn_rfc2141 | Urn RFC 2141 String |
|
||||
|
||||
@@ -133,6 +135,7 @@ validate := validator.New(validator.WithRequiredStructEnabled())
|
||||
| Tag | Description |
|
||||
| - | - |
|
||||
| alpha | Alpha Only |
|
||||
| alphaspace | Alpha Space |
|
||||
| alphanum | Alphanumeric |
|
||||
| alphanumunicode | Alphanumeric Unicode |
|
||||
| alphaunicode | Alpha Unicode |
|
||||
|
||||
+39
@@ -118,6 +118,7 @@ var (
|
||||
"fieldcontains": fieldContains,
|
||||
"fieldexcludes": fieldExcludes,
|
||||
"alpha": isAlpha,
|
||||
"alphaspace": isAlphaSpace,
|
||||
"alphanum": isAlphanum,
|
||||
"alphaunicode": isAlphaUnicode,
|
||||
"alphanumunicode": isAlphanumUnicode,
|
||||
@@ -134,6 +135,7 @@ var (
|
||||
"email": isEmail,
|
||||
"url": isURL,
|
||||
"http_url": isHttpURL,
|
||||
"https_url": isHttpsURL,
|
||||
"uri": isURI,
|
||||
"urn_rfc2141": isUrnRFC2141, // RFC 2141
|
||||
"file": isFile,
|
||||
@@ -1513,6 +1515,29 @@ func isHttpURL(fl FieldLevel) bool {
|
||||
panic(fmt.Sprintf("Bad field type %s", field.Type()))
|
||||
}
|
||||
|
||||
// isHttpsURL is the validation function for validating if the current field's value is a valid HTTPS-only URL.
|
||||
func isHttpsURL(fl FieldLevel) bool {
|
||||
if !isURL(fl) {
|
||||
return false
|
||||
}
|
||||
|
||||
field := fl.Field()
|
||||
switch field.Kind() {
|
||||
case reflect.String:
|
||||
|
||||
s := strings.ToLower(field.String())
|
||||
|
||||
url, err := url.Parse(s)
|
||||
if err != nil || url.Host == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
return url.Scheme == "https"
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("Bad field type %s", field.Type()))
|
||||
}
|
||||
|
||||
// isUrnRFC2141 is the validation function for validating if the current field's value is a valid URN as per RFC 2141.
|
||||
func isUrnRFC2141(fl FieldLevel) bool {
|
||||
field := fl.Field()
|
||||
@@ -1743,6 +1768,11 @@ func isAlphanumUnicode(fl FieldLevel) bool {
|
||||
return alphaUnicodeNumericRegex().MatchString(fl.Field().String())
|
||||
}
|
||||
|
||||
// isAlphaSpace is the validation function for validating if the current field's value is a valid alpha value with spaces.
|
||||
func isAlphaSpace(fl FieldLevel) bool {
|
||||
return alphaSpaceRegex().MatchString(fl.Field().String())
|
||||
}
|
||||
|
||||
// isAlphaUnicode is the validation function for validating if the current field's value is a valid alpha unicode value.
|
||||
func isAlphaUnicode(fl FieldLevel) bool {
|
||||
return alphaUnicodeRegex().MatchString(fl.Field().String())
|
||||
@@ -1872,6 +1902,15 @@ func requiredIf(fl FieldLevel) bool {
|
||||
if len(params)%2 != 0 {
|
||||
panic(fmt.Sprintf("Bad param number for required_if %s", fl.FieldName()))
|
||||
}
|
||||
|
||||
seen := make(map[string]struct{})
|
||||
for i := 0; i < len(params); i += 2 {
|
||||
if _, ok := seen[params[i]]; ok {
|
||||
panic(fmt.Sprintf("Duplicate param %s for required_if %s", params[i], fl.FieldName()))
|
||||
}
|
||||
seen[params[i]] = struct{}{}
|
||||
}
|
||||
|
||||
for i := 0; i < len(params); i += 2 {
|
||||
if !requireCheckFieldValue(fl, params[i], params[i+1], false) {
|
||||
return true
|
||||
|
||||
+13
@@ -264,6 +264,7 @@ The field under validation must be present and not empty only if all
|
||||
the other specified fields are equal to the value following the specified
|
||||
field. For strings ensures value is not "". For slices, maps, pointers,
|
||||
interfaces, channels and functions ensures the value is not nil. For structs ensures value is not the zero value.
|
||||
Using the same field name multiple times in the parameters will result in a panic at runtime.
|
||||
|
||||
Usage: required_if
|
||||
|
||||
@@ -776,6 +777,12 @@ This validates that a string value contains ASCII alpha characters only
|
||||
|
||||
Usage: alpha
|
||||
|
||||
# Alpha Space
|
||||
|
||||
This validates that a string value contains ASCII alpha characters and spaces only
|
||||
|
||||
Usage: alphaspace
|
||||
|
||||
# Alphanumeric
|
||||
|
||||
This validates that a string value contains ASCII alphanumeric characters only
|
||||
@@ -1330,6 +1337,12 @@ can be used to validate fields typically passed to sockets and connections.
|
||||
|
||||
Usage: hostname_port
|
||||
|
||||
# Port
|
||||
|
||||
This validates that the value falls within the valid port number range of 1 to 65,535.
|
||||
|
||||
Usage: port
|
||||
|
||||
# Datetime
|
||||
|
||||
This validates that a string value is a valid datetime based on the supplied datetime format.
|
||||
|
||||
+2
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
const (
|
||||
alphaRegexString = "^[a-zA-Z]+$"
|
||||
alphaSpaceRegexString = "^[a-zA-Z ]+$"
|
||||
alphaNumericRegexString = "^[a-zA-Z0-9]+$"
|
||||
alphaUnicodeRegexString = "^[\\p{L}]+$"
|
||||
alphaUnicodeNumericRegexString = "^[\\p{L}\\p{N}]+$"
|
||||
@@ -93,6 +94,7 @@ func lazyRegexCompile(str string) func() *regexp.Regexp {
|
||||
|
||||
var (
|
||||
alphaRegex = lazyRegexCompile(alphaRegexString)
|
||||
alphaSpaceRegex = lazyRegexCompile(alphaSpaceRegexString)
|
||||
alphaNumericRegex = lazyRegexCompile(alphaNumericRegexString)
|
||||
alphaUnicodeRegex = lazyRegexCompile(alphaUnicodeRegexString)
|
||||
alphaUnicodeNumericRegex = lazyRegexCompile(alphaUnicodeNumericRegexString)
|
||||
|
||||
+59
-1
@@ -181,7 +181,7 @@ func (v Validate) ValidateMapCtx(ctx context.Context, data map[string]interface{
|
||||
errs[field] = errors.New("The field: '" + field + "' is not a map to dive")
|
||||
}
|
||||
} else if ruleStr, ok := rule.(string); ok {
|
||||
err := v.VarCtx(ctx, data[field], ruleStr)
|
||||
err := v.VarWithKeyCtx(ctx, field, data[field], ruleStr)
|
||||
if err != nil {
|
||||
errs[field] = err
|
||||
}
|
||||
@@ -681,6 +681,64 @@ func (v *Validate) VarWithValueCtx(ctx context.Context, field interface{}, other
|
||||
return
|
||||
}
|
||||
|
||||
// VarWithKey validates a single variable with a key to be included in the returned error using tag style validation
|
||||
// eg.
|
||||
// var s string
|
||||
// validate.VarWithKey("email_address", s, "required,email")
|
||||
//
|
||||
// WARNING: a struct can be passed for validation eg. time.Time is a struct or
|
||||
// if you have a custom type and have registered a custom type handler, so must
|
||||
// allow it; however unforeseen validations will occur if trying to validate a
|
||||
// struct that is meant to be passed to 'validate.Struct'
|
||||
//
|
||||
// It returns InvalidValidationError for bad values passed in and nil or ValidationErrors as error otherwise.
|
||||
// You will need to assert the error if it's not nil eg. err.(validator.ValidationErrors) to access the array of errors.
|
||||
// validate Array, Slice and maps fields which may contain more than one error
|
||||
func (v *Validate) VarWithKey(key string, field interface{}, tag string) error {
|
||||
return v.VarWithKeyCtx(context.Background(), key, field, tag)
|
||||
}
|
||||
|
||||
// VarWithKeyCtx validates a single variable with a key to be included in the returned error using tag style validation
|
||||
// and allows passing of contextual validation information via context.Context.
|
||||
// eg.
|
||||
// var s string
|
||||
// validate.VarWithKeyCtx("email_address", s, "required,email")
|
||||
//
|
||||
// WARNING: a struct can be passed for validation eg. time.Time is a struct or
|
||||
// if you have a custom type and have registered a custom type handler, so must
|
||||
// allow it; however unforeseen validations will occur if trying to validate a
|
||||
// struct that is meant to be passed to 'validate.Struct'
|
||||
//
|
||||
// It returns InvalidValidationError for bad values passed in and nil or ValidationErrors as error otherwise.
|
||||
// You will need to assert the error if it's not nil eg. err.(validator.ValidationErrors) to access the array of errors.
|
||||
// validate Array, Slice and maps fields which may contain more than one error
|
||||
func (v *Validate) VarWithKeyCtx(ctx context.Context, key string, field interface{}, tag string) (err error) {
|
||||
if len(tag) == 0 || tag == skipValidationTag {
|
||||
return nil
|
||||
}
|
||||
|
||||
ctag := v.fetchCacheTag(tag)
|
||||
|
||||
cField := &cField{
|
||||
name: key,
|
||||
altName: key,
|
||||
namesEqual: true,
|
||||
}
|
||||
|
||||
val := reflect.ValueOf(field)
|
||||
vd := v.pool.Get().(*validate)
|
||||
vd.top = val
|
||||
vd.isPartial = false
|
||||
vd.traverseField(ctx, val, val, vd.ns[0:0], vd.actualNs[0:0], cField, ctag)
|
||||
|
||||
if len(vd.errs) > 0 {
|
||||
err = vd.errs
|
||||
vd.errs = nil
|
||||
}
|
||||
v.pool.Put(vd)
|
||||
return
|
||||
}
|
||||
|
||||
func (v *Validate) registerValidation(tag string, fn FuncCtx, bakedIn bool, nilCheckable bool) error {
|
||||
if len(tag) == 0 {
|
||||
return errors.New("function Key cannot be empty")
|
||||
|
||||
Reference in New Issue
Block a user