Skip to content

Commit 97d2bf0

Browse files
KimNorgaardmaltsev25violin0622Dean KarnDean Karn
authored
Fix length check on dns_rfc1035_label tag (#1214)
## 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>
1 parent 98aa9f2 commit 97d2bf0

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

baked_in.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,7 +1376,6 @@ func isEqIgnoreCase(fl FieldLevel) bool {
13761376
param := fl.Param()
13771377

13781378
switch field.Kind() {
1379-
13801379
case reflect.String:
13811380
return strings.EqualFold(field.String(), param)
13821381
}
@@ -1606,7 +1605,6 @@ func isImage(fl FieldLevel) bool {
16061605
case reflect.String:
16071606
filePath := field.String()
16081607
fileInfo, err := os.Stat(filePath)
1609-
16101608
if err != nil {
16111609
return false
16121610
}
@@ -1635,7 +1633,6 @@ func isImage(fl FieldLevel) bool {
16351633

16361634
// isFilePath is the validation function for validating if the current field's value is a valid file path.
16371635
func isFilePath(fl FieldLevel) bool {
1638-
16391636
var exists bool
16401637
var err error
16411638

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

22292226
if field.Type().ConvertibleTo(timeType) {
2230-
22312227
return field.Convert(timeType).Interface().(time.Time).After(time.Now().UTC())
22322228
}
22332229
}
@@ -2464,7 +2460,6 @@ func isLt(fl FieldLevel) bool {
24642460
case reflect.Struct:
24652461

24662462
if field.Type().ConvertibleTo(timeType) {
2467-
24682463
return field.Convert(timeType).Interface().(time.Time).Before(time.Now().UTC())
24692464
}
24702465
}
@@ -2644,7 +2639,6 @@ func isDir(fl FieldLevel) bool {
26442639

26452640
// isDirPath is the validation function for validating if the current field's value is a valid directory.
26462641
func isDirPath(fl FieldLevel) bool {
2647-
26482642
var exists bool
26492643
var err error
26502644

@@ -2957,6 +2951,12 @@ func isCveFormat(fl FieldLevel) bool {
29572951
// a valid dns RFC 1035 label, defined in RFC 1035.
29582952
func isDnsRFC1035LabelFormat(fl FieldLevel) bool {
29592953
val := fl.Field().String()
2954+
2955+
size := len(val)
2956+
if size > 63 {
2957+
return false
2958+
}
2959+
29602960
return dnsRegexRFC1035Label().MatchString(val)
29612961
}
29622962

regexes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const (
6969
splitParamsRegexString = `'[^']*'|\S+`
7070
bicRegexString = `^[A-Za-z]{6}[A-Za-z0-9]{2}([A-Za-z0-9]{3})?$`
7171
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/
72-
dnsRegexStringRFC1035Label = "^[a-z]([-a-z0-9]*[a-z0-9]){0,62}$"
72+
dnsRegexStringRFC1035Label = "^[a-z]([-a-z0-9]*[a-z0-9])?$"
7373
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
7474
mongodbIdRegexString = "^[a-f\\d]{24}$"
7575
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]+))?)*)?$"

validator_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13243,6 +13243,8 @@ func TestRFC1035LabelFormatValidation(t *testing.T) {
1324313243
{"ABC-ABC", "dns_rfc1035_label", false},
1324413244
{"123-abc", "dns_rfc1035_label", false},
1324513245
{"", "dns_rfc1035_label", false},
13246+
{"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk", "dns_rfc1035_label", true},
13247+
{"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl", "dns_rfc1035_label", false},
1324613248
}
1324713249

1324813250
validate := New()

0 commit comments

Comments
 (0)