Skip to content

Aliases or'ed with other functions causes a panic Undefined validation function #766

Open
@BrianLeishman

Description

@BrianLeishman

Package version eg. v9, v10:

v10

Issue, Question or Enhancement:

Custom validation aliases with "or" (|) panic with Undefined validation function

Code sample, to showcase or reproduce:

I use a custom alias for custom identifiers, that's an alias including a custom function

const rawBase64URLRegexString = "^[A-Za-z0-9-_]*$"
var rawBase64URLRegex = regexp.MustCompile(rawBase64URLRegexString)
v.validate.RegisterValidation("rawbase64url", func(fl validator.FieldLevel) bool {
	return rawBase64URLRegex.MatchString(fl.Field().String())
})
v.validate.RegisterAlias("bid2", "rawbase64url,len=11")
var req struct {
	Order string `binding:"numeric|bid2"`
}

This results in a panic with Undefined validation function. However, this does not result in a panic and works great:

var req struct {
	Order string `binding:"bid2"`
}

Using a custom function (not an alias) also seems to work without issues

var req struct {
	Order string `binding:"rawbase64url|numeric"`
}

Upon further testing, it seems that even built in aliases fail when or'ed. The following also panics with Undefined validation function 'iscolor' on field 'Order'

var req struct {
	Order string `binding:"numeric|iscolor"`
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions