bump reva and deps
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
This commit is contained in:
+1
@@ -32,6 +32,7 @@ linters:
|
||||
- maintidx
|
||||
- misspell
|
||||
- mnd
|
||||
- modernize
|
||||
- nakedret
|
||||
- nestif
|
||||
- nilnil
|
||||
|
||||
+4
-1
@@ -123,6 +123,7 @@ validate := validator.New(validator.WithRequiredStructEnabled())
|
||||
| udp6_addr | User Datagram Protocol Address UDPv6 |
|
||||
| udp_addr | User Datagram Protocol Address UDP |
|
||||
| unix_addr | Unix domain socket end point Address |
|
||||
| uds_exists | Unix domain socket exists (checks filesystem sockets and Linux abstract sockets) |
|
||||
| uri | URI String |
|
||||
| url | URL String |
|
||||
| http_url | HTTP(s) URL String |
|
||||
@@ -137,6 +138,7 @@ validate := validator.New(validator.WithRequiredStructEnabled())
|
||||
| alpha | Alpha Only |
|
||||
| alphaspace | Alpha Space |
|
||||
| alphanum | Alphanumeric |
|
||||
| alphanumspace | Alphanumeric Space |
|
||||
| alphanumunicode | Alphanumeric Unicode |
|
||||
| alphaunicode | Alpha Unicode |
|
||||
| ascii | ASCII |
|
||||
@@ -164,7 +166,8 @@ validate := validator.New(validator.WithRequiredStructEnabled())
|
||||
| base64 | Base64 String |
|
||||
| base64url | Base64URL String |
|
||||
| base64rawurl | Base64RawURL String |
|
||||
| bic | Business Identifier Code (ISO 9362) |
|
||||
| bic_iso_9362_2014 | Business Identifier Code (ISO 9362:2014) |
|
||||
| bic | Business Identifier Code (ISO 9362:2022) |
|
||||
| bcp47_language_tag | Language tag (BCP 47) |
|
||||
| btc_addr | Bitcoin Address |
|
||||
| btc_addr_bech32 | Bitcoin Bech32 Address (segwit) |
|
||||
|
||||
+99
-9
@@ -1,6 +1,7 @@
|
||||
package validator
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"cmp"
|
||||
"context"
|
||||
@@ -15,6 +16,7 @@ import (
|
||||
"net/url"
|
||||
"os"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -120,6 +122,7 @@ var (
|
||||
"alpha": isAlpha,
|
||||
"alphaspace": isAlphaSpace,
|
||||
"alphanum": isAlphanum,
|
||||
"alphanumspace": isAlphaNumericSpace,
|
||||
"alphaunicode": isAlphaUnicode,
|
||||
"alphanumunicode": isAlphanumUnicode,
|
||||
"boolean": isBoolean,
|
||||
@@ -205,6 +208,7 @@ var (
|
||||
"ip6_addr": isIP6AddrResolvable,
|
||||
"ip_addr": isIPAddrResolvable,
|
||||
"unix_addr": isUnixAddrResolvable,
|
||||
"uds_exists": isUnixDomainSocketExists,
|
||||
"mac": isMAC,
|
||||
"hostname": isHostnameRFC952, // RFC 952
|
||||
"hostname_rfc1123": isHostnameRFC1123, // RFC 1123
|
||||
@@ -237,7 +241,8 @@ var (
|
||||
"bcp47_language_tag": isBCP47LanguageTag,
|
||||
"postcode_iso3166_alpha2": isPostcodeByIso3166Alpha2,
|
||||
"postcode_iso3166_alpha2_field": isPostcodeByIso3166Alpha2Field,
|
||||
"bic": isIsoBicFormat,
|
||||
"bic_iso_9362_2014": isIsoBic2014Format,
|
||||
"bic": isIsoBic2022Format,
|
||||
"semver": isSemverFormat,
|
||||
"dns_rfc1035_label": isDnsRFC1035LabelFormat,
|
||||
"credit_card": isCreditCard,
|
||||
@@ -533,12 +538,20 @@ func hasMultiByteCharacter(fl FieldLevel) bool {
|
||||
|
||||
// isPrintableASCII is the validation function for validating if the field's value is a valid printable ASCII character.
|
||||
func isPrintableASCII(fl FieldLevel) bool {
|
||||
return printableASCIIRegex().MatchString(fl.Field().String())
|
||||
field := fl.Field()
|
||||
if field.Kind() == reflect.String {
|
||||
return printableASCIIRegex().MatchString(field.String())
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// isASCII is the validation function for validating if the field's value is a valid ASCII character.
|
||||
func isASCII(fl FieldLevel) bool {
|
||||
return aSCIIRegex().MatchString(fl.Field().String())
|
||||
field := fl.Field()
|
||||
if field.Kind() == reflect.String {
|
||||
return aSCIIRegex().MatchString(field.String())
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// isUUID5 is the validation function for validating if the field's value is a valid v5 UUID.
|
||||
@@ -1773,6 +1786,11 @@ func isAlphaSpace(fl FieldLevel) bool {
|
||||
return alphaSpaceRegex().MatchString(fl.Field().String())
|
||||
}
|
||||
|
||||
// isAlphaNumericSpace is the validation function for validating if the current field's value is a valid alphanumeric value with spaces.
|
||||
func isAlphaNumericSpace(fl FieldLevel) bool {
|
||||
return alphanNumericSpaceRegex().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())
|
||||
@@ -1974,11 +1992,12 @@ func excludedUnless(fl FieldLevel) bool {
|
||||
panic(fmt.Sprintf("Bad param number for excluded_unless %s", fl.FieldName()))
|
||||
}
|
||||
for i := 0; i < len(params); i += 2 {
|
||||
if !requireCheckFieldValue(fl, params[i], params[i+1], false) {
|
||||
return !hasValue(fl)
|
||||
if requireCheckFieldValue(fl, params[i], params[i+1], false) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return true
|
||||
|
||||
return !hasValue(fl)
|
||||
}
|
||||
|
||||
// excludedWith is the validation function
|
||||
@@ -2595,6 +2614,70 @@ func isUnixAddrResolvable(fl FieldLevel) bool {
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// isUnixDomainSocketExists is the validation function for validating if the field's value is an existing Unix domain socket.
|
||||
// It handles both filesystem-based sockets and Linux abstract sockets.
|
||||
// It always returns false for Windows.
|
||||
func isUnixDomainSocketExists(fl FieldLevel) bool {
|
||||
if runtime.GOOS == "windows" {
|
||||
return false
|
||||
}
|
||||
|
||||
sockpath := fl.Field().String()
|
||||
|
||||
if sockpath == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
// On Linux, check for abstract sockets (prefixed with @)
|
||||
if runtime.GOOS == "linux" && strings.HasPrefix(sockpath, "@") {
|
||||
return isAbstractSocketExists(sockpath)
|
||||
}
|
||||
|
||||
// For filesystem-based sockets, check if the path exists and is a socket
|
||||
stats, err := os.Stat(sockpath)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return stats.Mode().Type() == fs.ModeSocket
|
||||
}
|
||||
|
||||
// isAbstractSocketExists checks if a Linux abstract socket exists by reading /proc/net/unix.
|
||||
// Abstract sockets are identified by an @ prefix in human-readable form.
|
||||
func isAbstractSocketExists(sockpath string) bool {
|
||||
file, err := os.Open("/proc/net/unix")
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
defer func() {
|
||||
_ = file.Close()
|
||||
}()
|
||||
|
||||
scanner := bufio.NewScanner(file)
|
||||
|
||||
// Skip the header line
|
||||
if !scanner.Scan() {
|
||||
return false
|
||||
}
|
||||
|
||||
// Abstract sockets in /proc/net/unix are represented with @ prefix
|
||||
// The socket path is the last field in each line
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
fields := strings.Fields(line)
|
||||
|
||||
// The path is the last field (8th field typically)
|
||||
if len(fields) >= 8 {
|
||||
path := fields[len(fields)-1]
|
||||
if path == sockpath {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func isIP4Addr(fl FieldLevel) bool {
|
||||
val := fl.Field().String()
|
||||
|
||||
@@ -2943,11 +3026,18 @@ func isBCP47LanguageTag(fl FieldLevel) bool {
|
||||
panic(fmt.Sprintf("Bad field type %s", field.Type()))
|
||||
}
|
||||
|
||||
// isIsoBicFormat is the validation function for validating if the current field's value is a valid Business Identifier Code (SWIFT code), defined in ISO 9362
|
||||
func isIsoBicFormat(fl FieldLevel) bool {
|
||||
// isIsoBic2014Format is the validation function for validating if the current field's value is a valid Business Identifier Code (SWIFT code), defined in ISO 9362 2014
|
||||
func isIsoBic2014Format(fl FieldLevel) bool {
|
||||
bicString := fl.Field().String()
|
||||
|
||||
return bicRegex().MatchString(bicString)
|
||||
return bic2014Regex().MatchString(bicString)
|
||||
}
|
||||
|
||||
// isIsoBic2022Format is the validation function for validating if the current field's value is a valid Business Identifier Code (SWIFT code), defined in ISO 9362 2022
|
||||
func isIsoBic2022Format(fl FieldLevel) bool {
|
||||
bicString := fl.Field().String()
|
||||
|
||||
return bic2022Regex().MatchString(bicString)
|
||||
}
|
||||
|
||||
// isSemverFormat is the validation function for validating if the current field's value is a valid semver version, defined in Semantic Versioning 2.0.0
|
||||
|
||||
+18
@@ -289,6 +289,24 @@ func (v *Validate) parseFieldTagsRecursive(tag string, fieldName string, alias s
|
||||
if wrapper, ok := v.validations[current.tag]; ok {
|
||||
current.fn = wrapper.fn
|
||||
current.runValidationWhenNil = wrapper.runValidationOnNil
|
||||
} else if aliasTag, isAlias := v.aliases[current.tag]; isAlias {
|
||||
aliasFirst, aliasLast := v.parseFieldTagsRecursive(aliasTag, fieldName, current.tag, true)
|
||||
|
||||
current.tag = aliasFirst.tag
|
||||
current.fn = aliasFirst.fn
|
||||
current.runValidationWhenNil = aliasFirst.runValidationWhenNil
|
||||
current.hasParam = aliasFirst.hasParam
|
||||
current.param = aliasFirst.param
|
||||
current.typeof = aliasFirst.typeof
|
||||
current.hasAlias = true
|
||||
|
||||
if aliasFirst.next != nil {
|
||||
nextInChain := current.next
|
||||
current.next = aliasFirst.next
|
||||
aliasLast.next = nextInChain
|
||||
aliasLast.isBlockEnd = false
|
||||
current = aliasLast
|
||||
}
|
||||
} else {
|
||||
panic(strings.TrimSpace(fmt.Sprintf(undefinedValidation, current.tag, fieldName)))
|
||||
}
|
||||
|
||||
+6
-6
@@ -258,7 +258,7 @@ var iso3166_2 = map[string]struct{}{
|
||||
"BD-56": {}, "BD-57": {}, "BD-58": {}, "BD-59": {}, "BD-60": {},
|
||||
"BD-61": {}, "BD-62": {}, "BD-63": {}, "BD-64": {}, "BD-A": {},
|
||||
"BD-B": {}, "BD-C": {}, "BD-D": {}, "BD-E": {}, "BD-F": {},
|
||||
"BD-G": {}, "BE-BRU": {}, "BE-VAN": {}, "BE-VBR": {}, "BE-VLG": {},
|
||||
"BD-G": {}, "BD-H": {}, "BE-BRU": {}, "BE-VAN": {}, "BE-VBR": {}, "BE-VLG": {},
|
||||
"BE-VLI": {}, "BE-VOV": {}, "BE-VWV": {}, "BE-WAL": {}, "BE-WBR": {},
|
||||
"BE-WHT": {}, "BE-WLG": {}, "BE-WLX": {}, "BE-WNA": {}, "BF-01": {},
|
||||
"BF-02": {}, "BF-03": {}, "BF-04": {}, "BF-05": {}, "BF-06": {},
|
||||
@@ -573,7 +573,7 @@ var iso3166_2 = map[string]struct{}{
|
||||
"ID-KB": {}, "ID-KI": {}, "ID-KU": {}, "ID-KR": {}, "ID-KS": {},
|
||||
"ID-KT": {}, "ID-LA": {}, "ID-MA": {}, "ID-ML": {}, "ID-MU": {},
|
||||
"ID-NB": {}, "ID-NT": {}, "ID-NU": {}, "ID-PA": {}, "ID-PB": {},
|
||||
"ID-PE": {}, "ID-PP": {}, "ID-PS": {}, "ID-PT": {}, "ID-RI": {},
|
||||
"ID-PD": {}, "ID-PE": {}, "ID-PP": {}, "ID-PS": {}, "ID-PT": {}, "ID-RI": {},
|
||||
"ID-SA": {}, "ID-SB": {}, "ID-SG": {}, "ID-SL": {}, "ID-SM": {},
|
||||
"ID-SN": {}, "ID-SR": {}, "ID-SS": {}, "ID-ST": {}, "ID-SU": {},
|
||||
"ID-YO": {}, "IE-C": {}, "IE-CE": {}, "IE-CN": {}, "IE-CO": {},
|
||||
@@ -587,7 +587,7 @@ var iso3166_2 = map[string]struct{}{
|
||||
"IN-AS": {}, "IN-BR": {}, "IN-CH": {}, "IN-CT": {}, "IN-DH": {},
|
||||
"IN-DL": {}, "IN-DN": {}, "IN-GA": {}, "IN-GJ": {}, "IN-HP": {},
|
||||
"IN-HR": {}, "IN-JH": {}, "IN-JK": {}, "IN-KA": {}, "IN-KL": {},
|
||||
"IN-LD": {}, "IN-MH": {}, "IN-ML": {}, "IN-MN": {}, "IN-MP": {},
|
||||
"IN-LA": {}, "IN-LD": {}, "IN-MH": {}, "IN-ML": {}, "IN-MN": {}, "IN-MP": {},
|
||||
"IN-MZ": {}, "IN-NL": {}, "IN-TG": {}, "IN-OR": {}, "IN-PB": {}, "IN-PY": {},
|
||||
"IN-RJ": {}, "IN-SK": {}, "IN-TN": {}, "IN-TR": {}, "IN-UP": {},
|
||||
"IN-UT": {}, "IN-WB": {}, "IQ-AN": {}, "IQ-AR": {}, "IQ-BA": {},
|
||||
@@ -667,7 +667,7 @@ var iso3166_2 = map[string]struct{}{
|
||||
"KP-08": {}, "KP-09": {}, "KP-10": {}, "KP-13": {}, "KR-11": {},
|
||||
"KR-26": {}, "KR-27": {}, "KR-28": {}, "KR-29": {}, "KR-30": {},
|
||||
"KR-31": {}, "KR-41": {}, "KR-42": {}, "KR-43": {}, "KR-44": {},
|
||||
"KR-45": {}, "KR-46": {}, "KR-47": {}, "KR-48": {}, "KR-49": {},
|
||||
"KR-45": {}, "KR-46": {}, "KR-47": {}, "KR-48": {}, "KR-49": {}, "KR-50": {},
|
||||
"KW-AH": {}, "KW-FA": {}, "KW-HA": {}, "KW-JA": {}, "KW-KU": {},
|
||||
"KW-MU": {}, "KZ-10": {}, "KZ-75": {}, "KZ-19": {}, "KZ-11": {},
|
||||
"KZ-15": {}, "KZ-71": {}, "KZ-23": {}, "KZ-27": {}, "KZ-47": {},
|
||||
@@ -758,7 +758,7 @@ var iso3166_2 = map[string]struct{}{
|
||||
"ME-02": {}, "ME-03": {}, "ME-04": {}, "ME-05": {}, "ME-06": {},
|
||||
"ME-07": {}, "ME-08": {}, "ME-09": {}, "ME-10": {}, "ME-11": {},
|
||||
"ME-12": {}, "ME-13": {}, "ME-14": {}, "ME-15": {}, "ME-16": {},
|
||||
"ME-17": {}, "ME-18": {}, "ME-19": {}, "ME-20": {}, "ME-21": {}, "ME-24": {},
|
||||
"ME-17": {}, "ME-18": {}, "ME-19": {}, "ME-20": {}, "ME-21": {}, "ME-22": {}, "ME-23": {}, "ME-24": {}, "ME-25": {},
|
||||
"MG-A": {}, "MG-D": {}, "MG-F": {}, "MG-M": {}, "MG-T": {},
|
||||
"MG-U": {}, "MH-ALK": {}, "MH-ALL": {}, "MH-ARN": {}, "MH-AUR": {},
|
||||
"MH-EBO": {}, "MH-ENI": {}, "MH-JAB": {}, "MH-JAL": {}, "MH-KIL": {},
|
||||
@@ -856,7 +856,7 @@ var iso3166_2 = map[string]struct{}{
|
||||
"NO-22": {}, "NP-1": {}, "NP-2": {}, "NP-3": {}, "NP-4": {},
|
||||
"NP-5": {}, "NP-BA": {}, "NP-BH": {}, "NP-DH": {}, "NP-GA": {},
|
||||
"NP-JA": {}, "NP-KA": {}, "NP-KO": {}, "NP-LU": {}, "NP-MA": {},
|
||||
"NP-ME": {}, "NP-NA": {}, "NP-RA": {}, "NP-SA": {}, "NP-SE": {},
|
||||
"NP-ME": {}, "NP-NA": {}, "NP-P1": {}, "NP-P2": {}, "NP-P3": {}, "NP-P4": {}, "NP-P5": {}, "NP-P6": {}, "NP-P7": {}, "NP-RA": {}, "NP-SA": {}, "NP-SE": {},
|
||||
"NR-01": {}, "NR-02": {}, "NR-03": {}, "NR-04": {}, "NR-05": {},
|
||||
"NR-06": {}, "NR-07": {}, "NR-08": {}, "NR-09": {}, "NR-10": {},
|
||||
"NR-11": {}, "NR-12": {}, "NR-13": {}, "NR-14": {}, "NZ-AUK": {},
|
||||
|
||||
+58
-58
@@ -10,33 +10,33 @@ var iso4217 = map[string]struct{}{
|
||||
"BIF": {}, "CVE": {}, "KHR": {}, "XAF": {}, "CAD": {},
|
||||
"KYD": {}, "CLP": {}, "CLF": {}, "CNY": {}, "COP": {},
|
||||
"COU": {}, "KMF": {}, "CDF": {}, "NZD": {}, "CRC": {},
|
||||
"HRK": {}, "CUP": {}, "CUC": {}, "ANG": {}, "CZK": {},
|
||||
"DKK": {}, "DJF": {}, "DOP": {}, "EGP": {}, "SVC": {},
|
||||
"ERN": {}, "SZL": {}, "ETB": {}, "FKP": {}, "FJD": {},
|
||||
"XPF": {}, "GMD": {}, "GEL": {}, "GHS": {}, "GIP": {},
|
||||
"GTQ": {}, "GBP": {}, "GNF": {}, "GYD": {}, "HTG": {},
|
||||
"HNL": {}, "HKD": {}, "HUF": {}, "ISK": {}, "IDR": {},
|
||||
"XDR": {}, "IRR": {}, "IQD": {}, "ILS": {}, "JMD": {},
|
||||
"JPY": {}, "JOD": {}, "KZT": {}, "KES": {}, "KPW": {},
|
||||
"KRW": {}, "KWD": {}, "KGS": {}, "LAK": {}, "LBP": {},
|
||||
"LSL": {}, "ZAR": {}, "LRD": {}, "LYD": {}, "CHF": {},
|
||||
"MOP": {}, "MKD": {}, "MGA": {}, "MWK": {}, "MYR": {},
|
||||
"MVR": {}, "MRU": {}, "MUR": {}, "XUA": {}, "MXN": {},
|
||||
"MXV": {}, "MDL": {}, "MNT": {}, "MAD": {}, "MZN": {},
|
||||
"MMK": {}, "NAD": {}, "NPR": {}, "NIO": {}, "NGN": {},
|
||||
"OMR": {}, "PKR": {}, "PAB": {}, "PGK": {}, "PYG": {},
|
||||
"PEN": {}, "PHP": {}, "PLN": {}, "QAR": {}, "RON": {},
|
||||
"RUB": {}, "RWF": {}, "SHP": {}, "WST": {}, "STN": {},
|
||||
"SAR": {}, "RSD": {}, "SCR": {}, "SLL": {}, "SGD": {},
|
||||
"XSU": {}, "SBD": {}, "SOS": {}, "SSP": {}, "LKR": {},
|
||||
"SDG": {}, "SRD": {}, "SEK": {}, "CHE": {}, "CHW": {},
|
||||
"SYP": {}, "TWD": {}, "TJS": {}, "TZS": {}, "THB": {},
|
||||
"TOP": {}, "TTD": {}, "TND": {}, "TRY": {}, "TMT": {},
|
||||
"UGX": {}, "UAH": {}, "AED": {}, "USN": {}, "UYU": {},
|
||||
"UYI": {}, "UYW": {}, "UZS": {}, "VUV": {}, "VES": {},
|
||||
"VND": {}, "YER": {}, "ZMW": {}, "ZWL": {}, "XBA": {},
|
||||
"XBB": {}, "XBC": {}, "XBD": {}, "XTS": {}, "XXX": {},
|
||||
"XAU": {}, "XPD": {}, "XPT": {}, "XAG": {},
|
||||
"CUP": {}, "CZK": {}, "DKK": {}, "DJF": {}, "DOP": {},
|
||||
"EGP": {}, "SVC": {}, "ERN": {}, "SZL": {}, "ETB": {},
|
||||
"FKP": {}, "FJD": {}, "XPF": {}, "GMD": {}, "GEL": {},
|
||||
"GHS": {}, "GIP": {}, "GTQ": {}, "GBP": {}, "GNF": {},
|
||||
"GYD": {}, "HTG": {}, "HNL": {}, "HKD": {}, "HUF": {},
|
||||
"ISK": {}, "IDR": {}, "XDR": {}, "IRR": {}, "IQD": {},
|
||||
"ILS": {}, "JMD": {}, "JPY": {}, "JOD": {}, "KZT": {},
|
||||
"KES": {}, "KPW": {}, "KRW": {}, "KWD": {}, "KGS": {},
|
||||
"LAK": {}, "LBP": {}, "LSL": {}, "ZAR": {}, "LRD": {},
|
||||
"LYD": {}, "CHF": {}, "MOP": {}, "MKD": {}, "MGA": {},
|
||||
"MWK": {}, "MYR": {}, "MVR": {}, "MRU": {}, "MUR": {},
|
||||
"XUA": {}, "MXN": {}, "MXV": {}, "MDL": {}, "MNT": {},
|
||||
"MAD": {}, "MZN": {}, "MMK": {}, "NAD": {}, "NPR": {},
|
||||
"NIO": {}, "NGN": {}, "OMR": {}, "PKR": {}, "PAB": {},
|
||||
"PGK": {}, "PYG": {}, "PEN": {}, "PHP": {}, "PLN": {},
|
||||
"QAR": {}, "RON": {}, "RUB": {}, "RWF": {}, "SHP": {},
|
||||
"WST": {}, "STN": {}, "SAR": {}, "RSD": {}, "SCR": {},
|
||||
"SLE": {}, "SGD": {}, "XSU": {}, "SBD": {}, "SOS": {},
|
||||
"SSP": {}, "LKR": {}, "SDG": {}, "SRD": {}, "SEK": {},
|
||||
"CHE": {}, "CHW": {}, "SYP": {}, "TWD": {}, "TJS": {},
|
||||
"TZS": {}, "THB": {}, "TOP": {}, "TTD": {}, "TND": {},
|
||||
"TRY": {}, "TMT": {}, "UGX": {}, "UAH": {}, "AED": {},
|
||||
"USN": {}, "UYU": {}, "UYI": {}, "UYW": {}, "UZS": {},
|
||||
"VUV": {}, "VES": {}, "VED": {}, "VND": {}, "YER": {},
|
||||
"ZMW": {}, "ZWG": {}, "XBA": {}, "XBB": {}, "XBC": {},
|
||||
"XBD": {}, "XCG": {}, "XTS": {}, "XXX": {}, "XAU": {},
|
||||
"XPD": {}, "XPT": {}, "XAG": {},
|
||||
}
|
||||
|
||||
var iso4217_numeric = map[int]struct{}{
|
||||
@@ -45,35 +45,35 @@ var iso4217_numeric = map[int]struct{}{
|
||||
64: {}, 68: {}, 72: {}, 84: {}, 90: {},
|
||||
96: {}, 104: {}, 108: {}, 116: {}, 124: {},
|
||||
132: {}, 136: {}, 144: {}, 152: {}, 156: {},
|
||||
170: {}, 174: {}, 188: {}, 191: {}, 192: {},
|
||||
203: {}, 208: {}, 214: {}, 222: {}, 230: {},
|
||||
232: {}, 238: {}, 242: {}, 262: {}, 270: {},
|
||||
292: {}, 320: {}, 324: {}, 328: {}, 332: {},
|
||||
340: {}, 344: {}, 348: {}, 352: {}, 356: {},
|
||||
360: {}, 364: {}, 368: {}, 376: {}, 388: {},
|
||||
392: {}, 398: {}, 400: {}, 404: {}, 408: {},
|
||||
410: {}, 414: {}, 417: {}, 418: {}, 422: {},
|
||||
426: {}, 430: {}, 434: {}, 446: {}, 454: {},
|
||||
458: {}, 462: {}, 480: {}, 484: {}, 496: {},
|
||||
498: {}, 504: {}, 512: {}, 516: {}, 524: {},
|
||||
532: {}, 533: {}, 548: {}, 554: {}, 558: {},
|
||||
566: {}, 578: {}, 586: {}, 590: {}, 598: {},
|
||||
600: {}, 604: {}, 608: {}, 634: {}, 643: {},
|
||||
646: {}, 654: {}, 682: {}, 690: {}, 694: {},
|
||||
702: {}, 704: {}, 706: {}, 710: {}, 728: {},
|
||||
748: {}, 752: {}, 756: {}, 760: {}, 764: {},
|
||||
776: {}, 780: {}, 784: {}, 788: {}, 800: {},
|
||||
807: {}, 818: {}, 826: {}, 834: {}, 840: {},
|
||||
858: {}, 860: {}, 882: {}, 886: {}, 901: {},
|
||||
927: {}, 928: {}, 929: {}, 930: {}, 931: {},
|
||||
932: {}, 933: {}, 934: {}, 936: {}, 938: {},
|
||||
940: {}, 941: {}, 943: {}, 944: {}, 946: {},
|
||||
947: {}, 948: {}, 949: {}, 950: {}, 951: {},
|
||||
952: {}, 953: {}, 955: {}, 956: {}, 957: {},
|
||||
958: {}, 959: {}, 960: {}, 961: {}, 962: {},
|
||||
963: {}, 964: {}, 965: {}, 967: {}, 968: {},
|
||||
969: {}, 970: {}, 971: {}, 972: {}, 973: {},
|
||||
975: {}, 976: {}, 977: {}, 978: {}, 979: {},
|
||||
980: {}, 981: {}, 984: {}, 985: {}, 986: {},
|
||||
990: {}, 994: {}, 997: {}, 999: {},
|
||||
170: {}, 174: {}, 188: {}, 192: {}, 203: {},
|
||||
208: {}, 214: {}, 222: {}, 230: {}, 232: {},
|
||||
238: {}, 242: {}, 262: {}, 270: {}, 292: {},
|
||||
320: {}, 324: {}, 328: {}, 332: {}, 340: {},
|
||||
344: {}, 348: {}, 352: {}, 356: {}, 360: {},
|
||||
364: {}, 368: {}, 376: {}, 388: {}, 392: {},
|
||||
398: {}, 400: {}, 404: {}, 408: {}, 410: {},
|
||||
414: {}, 417: {}, 418: {}, 422: {}, 426: {},
|
||||
430: {}, 434: {}, 446: {}, 454: {}, 458: {},
|
||||
462: {}, 480: {}, 484: {}, 496: {}, 498: {},
|
||||
504: {}, 512: {}, 516: {}, 524: {}, 532: {},
|
||||
533: {}, 548: {}, 554: {}, 558: {}, 566: {},
|
||||
578: {}, 586: {}, 590: {}, 598: {}, 600: {},
|
||||
604: {}, 608: {}, 634: {}, 643: {}, 646: {},
|
||||
654: {}, 682: {}, 690: {}, 702: {}, 704: {},
|
||||
706: {}, 710: {}, 728: {}, 748: {}, 752: {},
|
||||
756: {}, 760: {}, 764: {}, 776: {}, 780: {},
|
||||
784: {}, 788: {}, 800: {}, 807: {}, 818: {},
|
||||
826: {}, 834: {}, 840: {}, 858: {}, 860: {},
|
||||
882: {}, 886: {}, 901: {}, 924: {}, 925: {},
|
||||
926: {}, 927: {}, 928: {}, 929: {}, 930: {},
|
||||
933: {}, 934: {}, 936: {}, 938: {}, 940: {},
|
||||
941: {}, 943: {}, 944: {}, 946: {}, 947: {},
|
||||
948: {}, 949: {}, 950: {}, 951: {}, 952: {},
|
||||
953: {}, 955: {}, 956: {}, 957: {}, 958: {},
|
||||
959: {}, 960: {}, 961: {}, 962: {}, 963: {},
|
||||
964: {}, 965: {}, 967: {}, 968: {}, 969: {},
|
||||
970: {}, 971: {}, 972: {}, 973: {}, 975: {},
|
||||
976: {}, 977: {}, 978: {}, 979: {}, 980: {},
|
||||
981: {}, 984: {}, 985: {}, 986: {}, 990: {},
|
||||
994: {}, 997: {}, 999: {},
|
||||
}
|
||||
|
||||
+35
-4
@@ -201,6 +201,15 @@ only for the nil-values).
|
||||
|
||||
Usage: omitnil
|
||||
|
||||
# Omit Zero
|
||||
|
||||
Allows to skip the validation if the value is a zero value.
|
||||
For pointers, it checks if the pointer is nil or the underlying value is a zero value.
|
||||
For slices and maps, it checks if the value is nil or empty.
|
||||
Otherwise, behaves the same as omitempty.
|
||||
|
||||
Usage: omitzero
|
||||
|
||||
# Dive
|
||||
|
||||
This tells the validator to dive into a slice, array or map and validate that
|
||||
@@ -789,6 +798,12 @@ This validates that a string value contains ASCII alphanumeric characters only
|
||||
|
||||
Usage: alphanum
|
||||
|
||||
# Alphanumeric Space
|
||||
|
||||
This validates that a string value contains ASCII alphanumeric characters and spaces only
|
||||
|
||||
Usage: alphanumspace
|
||||
|
||||
# Alpha Unicode
|
||||
|
||||
This validates that a string value contains unicode alpha characters only
|
||||
@@ -1263,6 +1278,15 @@ This validates that a string value contains a valid Unix Address.
|
||||
|
||||
Usage: unix_addr
|
||||
|
||||
# Unix Domain Socket Exists
|
||||
|
||||
This validates that a Unix domain socket file exists at the specified path.
|
||||
It checks both filesystem-based sockets and Linux abstract sockets (prefixed with @).
|
||||
For filesystem sockets, it verifies the path exists and is a socket file.
|
||||
For abstract sockets on Linux, it checks /proc/net/unix.
|
||||
|
||||
Usage: uds_exists
|
||||
|
||||
# Media Access Control Address MAC
|
||||
|
||||
This validates that a string value contains a valid MAC Address.
|
||||
@@ -1378,13 +1402,20 @@ More information on https://pkg.go.dev/golang.org/x/text/language
|
||||
|
||||
Usage: bcp47_language_tag
|
||||
|
||||
BIC (SWIFT code)
|
||||
BIC (SWIFT code - 2022 standard)
|
||||
|
||||
This validates that a string value is a valid Business Identifier Code (SWIFT code), defined in ISO 9362.
|
||||
More information on https://www.iso.org/standard/60390.html
|
||||
This validates that a string value is a valid Business Identifier Code (SWIFT code), defined in ISO 9362:2022.
|
||||
More information on https://www.iso.org/standard/84108.html
|
||||
|
||||
Usage: bic
|
||||
|
||||
BIC (SWIFT code - 2014 standard)
|
||||
|
||||
This validates that a string value is a valid Business Identifier Code (SWIFT code), defined in ISO 9362:2014.
|
||||
More information on https://www.iso.org/standard/60390.html
|
||||
|
||||
Usage: bic_iso_9362_2014
|
||||
|
||||
# RFC 1035 label
|
||||
|
||||
This validates that a string value is a valid dns RFC 1035 label, defined in RFC 1035.
|
||||
@@ -1519,7 +1550,7 @@ This package panics when bad input is provided, this is by design, bad code like
|
||||
that should not make it to production.
|
||||
|
||||
type Test struct {
|
||||
TestField string `validate:"nonexistantfunction=1"`
|
||||
TestField string `validate:"nonexistentfunction=1"`
|
||||
}
|
||||
|
||||
t := &Test{
|
||||
|
||||
+7
-3
@@ -9,6 +9,7 @@ const (
|
||||
alphaRegexString = "^[a-zA-Z]+$"
|
||||
alphaSpaceRegexString = "^[a-zA-Z ]+$"
|
||||
alphaNumericRegexString = "^[a-zA-Z0-9]+$"
|
||||
alphaNumericSpaceRegexString = "^[a-zA-Z0-9 ]+$"
|
||||
alphaUnicodeRegexString = "^[\\p{L}]+$"
|
||||
alphaUnicodeNumericRegexString = "^[\\p{L}\\p{N}]+$"
|
||||
numericRegexString = "^[-+]?[0-9]+(?:\\.[0-9]+)?$"
|
||||
@@ -20,7 +21,7 @@ const (
|
||||
hslRegexString = "^hsl\\(\\s*(?:0|[1-9]\\d?|[12]\\d\\d|3[0-5]\\d|360)\\s*,\\s*(?:(?:0|[1-9]\\d?|100)%)\\s*,\\s*(?:(?:0|[1-9]\\d?|100)%)\\s*\\)$"
|
||||
hslaRegexString = "^hsla\\(\\s*(?:0|[1-9]\\d?|[12]\\d\\d|3[0-5]\\d|360)\\s*,\\s*(?:(?:0|[1-9]\\d?|100)%)\\s*,\\s*(?:(?:0|[1-9]\\d?|100)%)\\s*,\\s*(?:(?:0.[1-9]*)|[01])\\s*\\)$"
|
||||
emailRegexString = "^(?:(?:(?:(?:[a-zA-Z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])+(?:\\.([a-zA-Z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])+)*)|(?:(?:\\x22)(?:(?:(?:(?:\\x20|\\x09)*(?:\\x0d\\x0a))?(?:\\x20|\\x09)+)?(?:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]|\\x21|[\\x23-\\x5b]|[\\x5d-\\x7e]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])|(?:(?:[\\x01-\\x09\\x0b\\x0c\\x0d-\\x7f]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}]))))*(?:(?:(?:\\x20|\\x09)*(?:\\x0d\\x0a))?(\\x20|\\x09)+)?(?:\\x22))))@(?:(?:(?:[a-zA-Z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])|(?:(?:[a-zA-Z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])(?:[a-zA-Z]|\\d|-|\\.|~|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])*(?:[a-zA-Z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])))\\.)+(?:(?:[a-zA-Z]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])|(?:(?:[a-zA-Z]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])(?:[a-zA-Z]|\\d|-|\\.|~|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])*(?:[a-zA-Z]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])))\\.?$"
|
||||
e164RegexString = "^\\+[1-9]?[0-9]{7,14}$"
|
||||
e164RegexString = "^\\+?[1-9]\\d{7,14}$"
|
||||
base32RegexString = "^(?:[A-Z2-7]{8})*(?:[A-Z2-7]{2}={6}|[A-Z2-7]{4}={4}|[A-Z2-7]{5}={3}|[A-Z2-7]{7}=|[A-Z2-7]{8})$"
|
||||
base64RegexString = "^(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}==|[A-Za-z0-9+\\/]{3}=|[A-Za-z0-9+\\/]{4})$"
|
||||
base64URLRegexString = "^(?:[A-Za-z0-9-_]{4})*(?:[A-Za-z0-9-_]{2}==|[A-Za-z0-9-_]{3}=|[A-Za-z0-9-_]{4})$"
|
||||
@@ -68,7 +69,8 @@ const (
|
||||
hTMLRegexString = `<[/]?([a-zA-Z]+).*?>`
|
||||
jWTRegexString = "^[A-Za-z0-9-_]+\\.[A-Za-z0-9-_]+\\.[A-Za-z0-9-_]*$"
|
||||
splitParamsRegexString = `'[^']*'|\S+`
|
||||
bicRegexString = `^[A-Za-z]{6}[A-Za-z0-9]{2}([A-Za-z0-9]{3})?$`
|
||||
bic2014RegexString = `^[A-Za-z]{6}[A-Za-z0-9]{2}([A-Za-z0-9]{3})?$`
|
||||
bic2022RegexString = `^[A-Z0-9]{4}[A-Z]{2}[A-Z0-9]{2}(?:[A-Z0-9]{3})?$`
|
||||
semverRegexString = `^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$` // numbered capture groups https://semver.org/
|
||||
dnsRegexStringRFC1035Label = "^[a-z]([-a-z0-9]*[a-z0-9])?$"
|
||||
cveRegexString = `^CVE-(1999|2\d{3})-(0[^0]\d{2}|0\d[^0]\d{1}|0\d{2}[^0]|[1-9]{1}\d{3,})$` // CVE Format Id https://cve.mitre.org/cve/identifiers/syntaxchange.html
|
||||
@@ -95,6 +97,7 @@ func lazyRegexCompile(str string) func() *regexp.Regexp {
|
||||
var (
|
||||
alphaRegex = lazyRegexCompile(alphaRegexString)
|
||||
alphaSpaceRegex = lazyRegexCompile(alphaSpaceRegexString)
|
||||
alphanNumericSpaceRegex = lazyRegexCompile(alphaNumericSpaceRegexString)
|
||||
alphaNumericRegex = lazyRegexCompile(alphaNumericRegexString)
|
||||
alphaUnicodeRegex = lazyRegexCompile(alphaUnicodeRegexString)
|
||||
alphaUnicodeNumericRegex = lazyRegexCompile(alphaUnicodeNumericRegexString)
|
||||
@@ -153,7 +156,8 @@ var (
|
||||
hTMLRegex = lazyRegexCompile(hTMLRegexString)
|
||||
jWTRegex = lazyRegexCompile(jWTRegexString)
|
||||
splitParamsRegex = lazyRegexCompile(splitParamsRegexString)
|
||||
bicRegex = lazyRegexCompile(bicRegexString)
|
||||
bic2014Regex = lazyRegexCompile(bic2014RegexString)
|
||||
bic2022Regex = lazyRegexCompile(bic2022RegexString)
|
||||
semverRegex = lazyRegexCompile(semverRegexString)
|
||||
dnsRegexRFC1035Label = lazyRegexCompile(dnsRegexStringRFC1035Label)
|
||||
cveRegex = lazyRegexCompile(cveRegexString)
|
||||
|
||||
+20
@@ -1074,6 +1074,26 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
|
||||
translation: "{0} can only contain alphanumeric characters",
|
||||
override: false,
|
||||
},
|
||||
{
|
||||
tag: "alphaspace",
|
||||
translation: "{0} can only contain alphabetic and space characters",
|
||||
override: false,
|
||||
},
|
||||
{
|
||||
tag: "alphanumspace",
|
||||
translation: "{0} can only contain alphanumeric and space characters",
|
||||
override: false,
|
||||
},
|
||||
{
|
||||
tag: "alphaunicode",
|
||||
translation: "{0} can only contain unicode alphabetic characters",
|
||||
override: false,
|
||||
},
|
||||
{
|
||||
tag: "alphanumunicode",
|
||||
translation: "{0} can only contain unicode alphanumeric characters",
|
||||
override: false,
|
||||
},
|
||||
{
|
||||
tag: "numeric",
|
||||
translation: "{0} must be a valid numeric value",
|
||||
|
||||
+3
-1
@@ -214,7 +214,9 @@ BEGIN:
|
||||
}
|
||||
|
||||
// if got here there was more namespace, cannot go any deeper
|
||||
panic("Invalid field namespace")
|
||||
// return found=false instead of panicking to handle cases like ValidateMap
|
||||
// where cross-field validators (required_if, etc.) can't navigate non-struct parents
|
||||
return
|
||||
}
|
||||
|
||||
// asInt returns the parameter as an int64
|
||||
|
||||
Reference in New Issue
Block a user