Repository: go-playground/validator
Pull request #1302 (2024-08-08 16:36:48)

fix: cron validation support for star step value
## Fixes Or Enhances
Resolves https://github.com/go-playground/validator/issues/1259

**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

coveralls: 
[![Coverage Status](https://coveralls.io/builds/69123141/badge)](https://coveralls.io/builds/69123141)

coverage: 74.291%. remained the same
when pulling **046c53ac3512e4ebfd5688c22a05f6135a7d5a5e on cgetzen-forks:cg/cron-validation-star-step-value**
into **a947377040f8ebaee09f20d09a745ec369396793 on go-playground:master**.

ccoVeille: Not related to your changes, but is format like 9-59/7 is correctly supported?

Patch:
diff --git a/README.md b/README.md
index 9ab0705..ddd65b0 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
 Package validator
 =================
 <img align="right" src="logo.png">[![Join the chat at https://gitter.im/go-playground/validator](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/go-playground/validator?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
-![Project status](https://img.shields.io/badge/version-10.22.0-green.svg)
+![Project status](https://img.shields.io/badge/version-10.22.1-green.svg)
 [![Build Status](https://travis-ci.org/go-playground/validator.svg?branch=master)](https://travis-ci.org/go-playground/validator)
 [![Coverage Status](https://coveralls.io/repos/go-playground/validator/badge.svg?branch=master&service=github)](https://coveralls.io/github/go-playground/validator?branch=master)
 [![Go Report Card](https://goreportcard.com/badge/github.com/go-playground/validator)](https://goreportcard.com/report/github.com/go-playground/validator)
diff --git a/baked_in.go b/baked_in.go
index b6fbaaf..d1a3656 100644
--- a/baked_in.go
+++ b/baked_in.go
@@ -1828,7 +1828,14 @@ func requireCheckFieldValue(
 		return int64(field.Len()) == asInt(value)
 
 	case reflect.Bool:
-		return field.Bool() == asBool(value)
+		return field.Bool() == (value == "true")
+
+	case reflect.Ptr:
+		if field.IsNil() {
+			return value == "nil"
+		}
+		// Handle non-nil pointers
+		return requireCheckFieldValue(fl, param, value, defaultNotFoundValue)
 	}
 
 	// default reflect.String:
diff --git a/regexes.go b/regexes.go
index 7e1dd5a..871cf7d 100644
--- a/regexes.go
+++ b/regexes.go
@@ -73,7 +73,7 @@ const (
 	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]+))?)*)?$"
-	cronRegexString                  = `(@(annually|yearly|monthly|weekly|daily|hourly|reboot))|(@every (\d+(ns|us|µs|ms|s|m|h))+)|((((\d+,)+\d+|(\d+(\/|-)\d+)|\d+|\*) ?){5,7})`
+	cronRegexString                  = `(@(annually|yearly|monthly|weekly|daily|hourly|reboot))|(@every (\d+(ns|us|µs|ms|s|m|h))+)|((((\d+,)+\d+|((\*|\d+)(\/|-)\d+)|\d+|\*) ?){5,7})`
 	spicedbIDRegexString             = `^(([a-zA-Z0-9/_|\-=+]{1,})|\*)$`
 	spicedbPermissionRegexString     = "^([a-z][a-z0-9_]{1,62}[a-z0-9])?$"
 	spicedbTypeRegexString           = "^([a-z][a-z0-9_]{1,61}[a-z0-9]/)?[a-z][a-z0-9_]{1,62}[a-z0-9]$"


Test patch:
diff --git a/validator_test.go b/validator_test.go
index 0f96b77..6bb5b29 100644
--- a/validator_test.go
+++ b/validator_test.go
@@ -12002,6 +12002,25 @@ func TestExcludedIf(t *testing.T) {
 	errs = validate.Struct(test10)
 	Equal(t, errs, nil)
 
+	test11 := struct {
+		Field1 bool
+  		Field2 *string `validate:"excluded_if=Field1 false"`
+	}{
+		Field1: false,
+		Field2: nil,
+	}
+	errs = validate.Struct(test11)
+	Equal(t, errs, nil)
+
+	test12 := struct {
+		Field1 bool
+		Field2 *string `validate:"excluded_if=Field1 !Field1"`
+	}{
+		Field1: true,
+		Field2: nil,
+	}
+	errs = validate.Struct(test12)
+	Equal(t, errs, nil)
 	// Checks number of params in struct tag is correct
 	defer func() {
 		if r := recover(); r == nil {
@@ -13637,6 +13656,7 @@ func TestCronExpressionValidation(t *testing.T) {
 		{"*/20 * * * *", "cron", true},
 		{"0 15 10 ? * MON-FRI", "cron", true},
 		{"0 15 10 ? * 6#3", "cron", true},
+		{"0 */15 * * *", "cron", true},
 		{"wrong", "cron", false},
 	}