Skip to content

Commit

Permalink
🐛 fix: fixed #11 reported bug
Browse files Browse the repository at this point in the history
  • Loading branch information
maktoobgar committed May 7, 2024
1 parent f2a6e73 commit 639a3ef
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CHANGELOG
UNRELEASED
----------

* 🐛 fix: fixed #11 reported bug

1.4.3 (2023-10-10)
------------------
Expand Down
15 changes: 15 additions & 0 deletions validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"reflect"
"regexp"
"strconv"
"strings"

Expand Down Expand Up @@ -489,12 +490,26 @@ func decryptPath(path string, v Validator, errorField playgroundValidator.FieldE
panic("error structure does not match with validator structure")
}
} else if rs := v.getRules(); len(rs) != 0 {
re, _ := regexp.Compile(`(\w+)\[(\d+)\]`)
slicePieces := re.FindStringSubmatch(fieldName)
arrayItem := -1
if len(slicePieces) > 0 {
fieldName = slicePieces[1]
arrayItem, _ = strconv.Atoi(slicePieces[2])
}
fmt.Println(fieldName)
if r, ok := rs[fieldName]; ok {
if deep := r.getDeepValidator(); deep != nil {
if r.getName() != "" {
fieldName = r.getName()
}
output[fieldName] = decryptPath(path, deep, errorField)
} else if children := r.getChildrenValidator(); arrayItem != -1 && children != nil {
if splits := strings.Split(path, "."); len(splits) == 1 && len(re.FindStringSubmatch(splits[0])) == 0 {
output[fieldName] = map[int]interface{}{arrayItem: map[string]interface{}{splits[0]: decryptPath(path, children, errorField)}}
} else {
output[fieldName] = map[int]interface{}{arrayItem: decryptPath(path, children, errorField)}
}
} else {
panic("error structure does not match with validator structure")
}
Expand Down

0 comments on commit 639a3ef

Please sign in to comment.