Skip to content

Commit

Permalink
Fix length check on dns_rfc1035_label tag (#1214)
Browse files Browse the repository at this point in the history
## Fixes Or Enhances

Fix length check on dns_rfc1035_label tag.

Fixes #1213 

**Make sure that you've checked the boxes below before you submit PR:**
- [x] Tests exist or have been written that cover this particular
change.

@go-playground/validator-maintainers

---------

Signed-off-by: pavedroad <qcqs@outlook.com>
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Gleb <49669778+maltsev25@users.noreply.github.com>
Co-authored-by: Violin <6880156+violin0622@users.noreply.github.com>
Co-authored-by: Dean Karn <Dean.Karn@gmail.com>
Co-authored-by: Dean Karn <deankarn@reaver1.local>
Co-authored-by: Nikolai Anohyn <82395127+nikolaianohyn@users.noreply.github.com>
Co-authored-by: nikolay <n.anohin@lucky.online>
Co-authored-by: Jian Yu <askingyj@gmail.com>
Co-authored-by: jamesatkin-myndup <125557880+jamesatkin-myndup@users.noreply.github.com>
Co-authored-by: Magnus Svensson <masv@sunet.se>
Co-authored-by: Ruslan Semagin <53819609+pixel365@users.noreply.github.com>
Co-authored-by: Nikita <nekit.nar10z@gmail.com>
Co-authored-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
Co-authored-by: Alex <42301971+alexongh@users.noreply.github.com>
Co-authored-by: Tomoki Nagata <45285704+Tomoki108@users.noreply.github.com>
Co-authored-by: pavedroad <138004431+pavedroad@users.noreply.github.com>
Co-authored-by: thinkofher <mail@bdudek.xyz>
Co-authored-by: Kyle Carberry <kyle@carberry.com>
Co-authored-by: Eugene <jhekasoft@gmail.com>
Co-authored-by: Ganeshdip Dumbare <ganeshdip.dumbare@gmail.com>
Co-authored-by: Charlie Getzen <charliegetzenlc@gmail.com>
Co-authored-by: Gabriel Augendre <gabriel@augendre.info>
Co-authored-by: Connor Carnes <connorcarnes44@gmail.com>
Co-authored-by: nodivbyzero <nodivbyzero@gmail.com>
Co-authored-by: Dean Karn <github@deankarn.com>
Co-authored-by: Daan Oosting <daan@devcap.nl>
Co-authored-by: wangxiaolei <fatelei@gmail.com>
Co-authored-by: Ganeshdip Dumbare <ganeshdip.dumbare@qonto.com>
Co-authored-by: zeewell <zeewell@gmail.com>
Co-authored-by: Anton Soroko <anton.soroko@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: fathiraz arthuro <arthurofathiraz@gmail.com>
Co-authored-by: 196Ikuchil <22634362+196Ikuchil@users.noreply.github.com>
  • Loading branch information
1 parent 98aa9f2 commit 97d2bf0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
12 changes: 6 additions & 6 deletions baked_in.go
Original file line number Diff line number Diff line change
Expand Up @@ -1376,7 +1376,6 @@ func isEqIgnoreCase(fl FieldLevel) bool {
param := fl.Param()

switch field.Kind() {

case reflect.String:
return strings.EqualFold(field.String(), param)
}
Expand Down Expand Up @@ -1606,7 +1605,6 @@ func isImage(fl FieldLevel) bool {
case reflect.String:
filePath := field.String()
fileInfo, err := os.Stat(filePath)

if err != nil {
return false
}
Expand Down Expand Up @@ -1635,7 +1633,6 @@ func isImage(fl FieldLevel) bool {

// isFilePath is the validation function for validating if the current field's value is a valid file path.
func isFilePath(fl FieldLevel) bool {

var exists bool
var err error

Expand Down Expand Up @@ -2227,7 +2224,6 @@ func isGt(fl FieldLevel) bool {
case reflect.Struct:

if field.Type().ConvertibleTo(timeType) {

return field.Convert(timeType).Interface().(time.Time).After(time.Now().UTC())
}
}
Expand Down Expand Up @@ -2464,7 +2460,6 @@ func isLt(fl FieldLevel) bool {
case reflect.Struct:

if field.Type().ConvertibleTo(timeType) {

return field.Convert(timeType).Interface().(time.Time).Before(time.Now().UTC())
}
}
Expand Down Expand Up @@ -2644,7 +2639,6 @@ func isDir(fl FieldLevel) bool {

// isDirPath is the validation function for validating if the current field's value is a valid directory.
func isDirPath(fl FieldLevel) bool {

var exists bool
var err error

Expand Down Expand Up @@ -2957,6 +2951,12 @@ func isCveFormat(fl FieldLevel) bool {
// a valid dns RFC 1035 label, defined in RFC 1035.
func isDnsRFC1035LabelFormat(fl FieldLevel) bool {
val := fl.Field().String()

size := len(val)
if size > 63 {
return false
}

return dnsRegexRFC1035Label().MatchString(val)
}

Expand Down
2 changes: 1 addition & 1 deletion regexes.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const (
splitParamsRegexString = `'[^']*'|\S+`
bicRegexString = `^[A-Za-z]{6}[A-Za-z0-9]{2}([A-Za-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]){0,62}$"
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
mongodbIdRegexString = "^[a-f\\d]{24}$"
mongodbConnStringRegexString = "^mongodb(\\+srv)?:\\/\\/(([a-zA-Z\\d]+):([a-zA-Z\\d$:\\/?#\\[\\]@]+)@)?(([a-z\\d.-]+)(:[\\d]+)?)((,(([a-z\\d.-]+)(:(\\d+))?))*)?(\\/[a-zA-Z-_]{1,64})?(\\?(([a-zA-Z]+)=([a-zA-Z\\d]+))(&(([a-zA-Z\\d]+)=([a-zA-Z\\d]+))?)*)?$"
Expand Down
2 changes: 2 additions & 0 deletions validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13243,6 +13243,8 @@ func TestRFC1035LabelFormatValidation(t *testing.T) {
{"ABC-ABC", "dns_rfc1035_label", false},
{"123-abc", "dns_rfc1035_label", false},
{"", "dns_rfc1035_label", false},
{"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk", "dns_rfc1035_label", true},
{"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl", "dns_rfc1035_label", false},
}

validate := New()
Expand Down

0 comments on commit 97d2bf0

Please sign in to comment.