nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: go-playground/validator
Pull request #547 (2019-11-19 19:03:11)

Added boolean type support for “eq” validator
Fixes Or Enhances # .
Added boolean type support for “eq” validator

**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.

Change Details:
added asBool function to convert string to boolean


@go-playground/admins


Patch:
diff --git a/baked_in.go b/baked_in.go
index 23f76b3..f80c315 100644
--- a/baked_in.go
+++ b/baked_in.go
@@ -1106,6 +1106,11 @@ func isEq(fl FieldLevel) bool {
 		p := asFloat(param)
 
 		return field.Float() == p
+
+	case reflect.Bool:
+		p := asBool(param)
+
+		return field.Bool() == p
 	}
 
 	panic(fmt.Sprintf("Bad field type %T", field.Interface()))
diff --git a/util.go b/util.go
index 71acbdc..0d3a181 100644
--- a/util.go
+++ b/util.go
@@ -249,6 +249,16 @@ func asFloat(param string) float64 {
 	return i
 }
 
+// asBool returns the parameter as a bool
+// or panics if it can't convert
+func asBool(param string) bool {
+
+	i, err := strconv.ParseBool(param)
+	panicIf(err)
+
+	return i
+}
+
 func panicIf(err error) {
 	if err != nil {
 		panic(err.Error())


Test patch:
diff --git a/validator_test.go b/validator_test.go
index 2787f9e..03264a2 100644
--- a/validator_test.go
+++ b/validator_test.go
@@ -7191,6 +7191,25 @@ func TestRequired(t *testing.T) {
 	AssertError(t, err.(ValidationErrors), "Test.Value", "Test.Value", "Value", "Value", "required")
 }
 
+func TestBoolEqual(t *testing.T) {
+
+	validate := New()
+
+	type Test struct {
+		Value bool `validate:"eq=true"`
+	}
+
+	var test Test
+
+	err := validate.Struct(test)
+	NotEqual(t, err, nil)
+	AssertError(t, err.(ValidationErrors), "Test.Value", "Test.Value", "Value", "Value", "eq")
+
+	test.Value = true
+	err = validate.Struct(test)
+	Equal(t, err, nil)
+}
+
 func TestTranslations(t *testing.T) {
 	en := en.New()
 	uni := ut.New(en, en, fr.New())
Repository: go-playground/validator
Pull request #600 (2020-04-19 06:20:26)

Fix/rfc952 host
Signed-off-by: amiraliucsc <amirali7089@gmail.com>

Fixes Or Enhances #599 .

**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.

Change Details:
This PR will change the hostnameRegexStringRFC952 to validate the dots only if one character is before the dot. This is to prevent considering string such as "example.....com" as a valid host. 

@go-playground/admins


Patch:
diff --git a/regexes.go b/regexes.go
index b8bf253..466eb80 100644
--- a/regexes.go
+++ b/regexes.go
@@ -36,7 +36,7 @@ const (
 	latitudeRegexString              = "^[-+]?([1-8]?\\d(\\.\\d+)?|90(\\.0+)?)$"
 	longitudeRegexString             = "^[-+]?(180(\\.0+)?|((1[0-7]\\d)|([1-9]?\\d))(\\.\\d+)?)$"
 	sSNRegexString                   = `^[0-9]{3}[ -]?(0[1-9]|[1-9][0-9])[ -]?([1-9][0-9]{3}|[0-9][1-9][0-9]{2}|[0-9]{2}[1-9][0-9]|[0-9]{3}[1-9])$`
-	hostnameRegexStringRFC952        = `^[a-zA-Z][a-zA-Z0-9\-\.]+[a-zA-Z0-9]$`                                            // https://tools.ietf.org/html/rfc952
+	hostnameRegexStringRFC952        = `^[a-zA-Z]([a-zA-Z0-9\-]+[\.]?)*[a-zA-Z0-9]$`                                      // https://tools.ietf.org/html/rfc952
 	hostnameRegexStringRFC1123       = `^([a-zA-Z0-9]{1}[a-zA-Z0-9_-]{0,62}){1}(\.[a-zA-Z0-9_]{1}[a-zA-Z0-9_-]{0,62})*?$` // accepts hostname starting with a digit https://tools.ietf.org/html/rfc1123
 	btcAddressRegexString            = `^[13][a-km-zA-HJ-NP-Z1-9]{25,34}$`                                                // bitcoin address
 	btcAddressUpperRegexStringBech32 = `^BC1[02-9AC-HJ-NP-Z]{7,76}$`                                                      // bitcoin bech32 address https://en.bitcoin.it/wiki/Bech32


Test patch:
diff --git a/validator_test.go b/validator_test.go
index 2e4215f..68e8132 100644
--- a/validator_test.go
+++ b/validator_test.go
@@ -7896,6 +7896,11 @@ func TestHostnameRFC952Validation(t *testing.T) {
 		{"2001:cdba:0000:0000:0000:0000:3257:9652", false},
 		{"2001:cdba:0:0:0:0:3257:9652", false},
 		{"2001:cdba::3257:9652", false},
+		{"example..........com", false},
+		{"1234", false},
+		{"abc1234", true},
+		{"example. com", false},
+		{"ex ample.com", false},
 	}
 
 	validate := New()
Repository: go-playground/validator
Pull request #609 (2020-05-10 14:06:14)

Add zh,zh_tw datetime translation
Fixes Or Enhances # .

**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.

Change Details:

- Add zh,zh_tw datetime translation


@go-playground/admins


Patch:
diff --git a/translations/zh_tw/zh_tw.go b/translations/zh_tw/zh_tw.go
index cf6f933..391a010 100644
--- a/translations/zh_tw/zh_tw.go
+++ b/translations/zh_tw/zh_tw.go
@@ -1304,6 +1304,21 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
 				return s
 			},
 		},
+		{
+			tag:         "datetime",
+			translation: "{0}與{1}格式不匹配",
+			override:    false,
+			customTransFunc: func(ut ut.Translator, fe validator.FieldError) string {
+
+				t, err := ut.T(fe.Tag(), fe.Field(), fe.Param())
+				if err != nil {
+					log.Printf("警告: 翻譯欄位錯誤: %#v", fe)
+					return fe.(error).Error()
+				}
+
+				return t
+			},
+		},
 	}
 
 	for _, t := range translations {


Test patch:
diff --git a/translations/zh_tw/zh_tw_test.go b/translations/zh_tw/zh_tw_test.go
index a4463a2..cf60d1d 100644
--- a/translations/zh_tw/zh_tw_test.go
+++ b/translations/zh_tw/zh_tw_test.go
@@ -4,9 +4,9 @@ import (
 	"testing"
 	"time"
 
+	. "github.com/go-playground/assert/v2"
 	zhongwen "github.com/go-playground/locales/zh_Hant_TW"
 	ut "github.com/go-playground/universal-translator"
-	. "github.com/go-playground/assert/v2"
 	"github.com/go-playground/validator/v10"
 )
 
@@ -138,6 +138,7 @@ func TestTranslations(t *testing.T) {
 		StrPtrGte         *string   `validate:"gte=10"`
 		OneOfString       string    `validate:"oneof=red green"`
 		OneOfInt          int       `validate:"oneof=5 63"`
+		Datetime          string    `validate:"datetime=2006-01-02"`
 	}
 
 	var test Test
@@ -184,6 +185,8 @@ func TestTranslations(t *testing.T) {
 	test.StrPtrMaxLen = &s
 	test.StrPtrLen = &s
 
+	test.Datetime = "2008-Feb-01"
+
 	err = validate.Struct(test)
 	NotEqual(t, err, nil)
 
@@ -614,6 +617,10 @@ func TestTranslations(t *testing.T) {
 			ns:       "Test.OneOfInt",
 			expected: "OneOfInt必須是[5 63]中的一個",
 		},
+		{
+			ns:       "Test.Datetime",
+			expected: "Datetime與2006-01-02格式不匹配",
+		},
 	}
 
 	for _, tt := range tests {