Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: go-playground/validator
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v10.6.1
Choose a base ref
...
head repository: go-playground/validator
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v10.6.2
Choose a head ref
  • 4 commits
  • 5 files changed
  • 4 contributors

Commits on Jul 8, 2021

  1. Copy the full SHA
    b1b32b2 View commit details
  2. Copy the full SHA
    90ab42b View commit details
  3. Update README.md

    Dean Karn authored Jul 8, 2021
    Copy the full SHA
    9104fe2 View commit details
  4. Update README.md (#786)

    arx111 authored Jul 8, 2021
    Copy the full SHA
    8bfa88a View commit details
Showing with 20 additions and 5 deletions.
  1. +2 −2 README.md
  2. +1 −1 translations/ja/ja.go
  3. +1 −1 translations/ja/ja_test.go
  4. +1 −1 validator.go
  5. +15 −0 validator_test.go
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package validator
=================
<img align="right" src="https://raw.githubusercontent.com/go-playground/validator/v9/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.6.1-green.svg)
![Project status](https://img.shields.io/badge/version-10.6.2-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)
@@ -43,7 +43,7 @@ They return type error to avoid the issue discussed in the following, where err
* http://stackoverflow.com/a/29138676/3158232
* https://github.com/go-playground/validator/issues/134

Validator only InvalidValidationError for bad validation input, nil or ValidationErrors as type error; so, in your code all you need to do is check if the error returned is not nil, and if it's not check if error is InvalidValidationError ( if necessary, most of the time it isn't ) type cast it to type ValidationErrors like so:
Validator returns only InvalidValidationError for bad validation input, nil or ValidationErrors as type error; so, in your code all you need to do is check if the error returned is not nil, and if it's not check if error is InvalidValidationError ( if necessary, most of the time it isn't ) type cast it to type ValidationErrors like so:

```go
err := validate.Struct(mystruct)
2 changes: 1 addition & 1 deletion translations/ja/ja.go
Original file line number Diff line number Diff line change
@@ -1226,7 +1226,7 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
},
{
tag: "uuid5",
translation: "{0}はバージョンが4の正しいUUIDでなければなりません",
translation: "{0}はバージョンが5の正しいUUIDでなければなりません",
override: false,
},
{
2 changes: 1 addition & 1 deletion translations/ja/ja_test.go
Original file line number Diff line number Diff line change
@@ -304,7 +304,7 @@ func TestTranslations(t *testing.T) {
},
{
ns: "Test.UUID5",
expected: "UUID5はバージョンが4の正しいUUIDでなければなりません",
expected: "UUID5はバージョンが5の正しいUUIDでなければなりません",
},
{
ns: "Test.ISBN",
2 changes: 1 addition & 1 deletion validator.go
Original file line number Diff line number Diff line change
@@ -227,7 +227,7 @@ func (v *validate) traverseField(ctx context.Context, parent reflect.Value, curr
}
}

if !ct.hasTag {
if ct == nil || !ct.hasTag {
return
}

15 changes: 15 additions & 0 deletions validator_test.go
Original file line number Diff line number Diff line change
@@ -3285,6 +3285,21 @@ func TestMapDiveValidation(t *testing.T) {
s := fmt.Sprint(errs.Error())
NotEqual(t, s, "")

type TestMapInterface struct {
Errs map[int]interface{} `validate:"dive"`
}

mit := map[int]interface{}{0: Inner{"ok"}, 1: Inner{""}, 3: nil, 5: "string", 6: 33}

msi := &TestMapInterface{
Errs: mit,
}

errs = validate.Struct(msi)
NotEqual(t, errs, nil)
Equal(t, len(errs.(ValidationErrors)), 1)
AssertError(t, errs, "TestMapInterface.Errs[1].Name", "TestMapInterface.Errs[1].Name", "Name", "Name", "required")

type TestMapTimeStruct struct {
Errs map[int]*time.Time `validate:"gt=0,dive,required"`
}