Skip to content

Commit

Permalink
validator
Browse files Browse the repository at this point in the history
  • Loading branch information
iesreza committed Mar 16, 2024
1 parent 0710085 commit 5fc3c36
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ func validateField(g *generic.Value, field *reflect.StructField) error {
if match := r.FindStringSubmatch(validator); len(match) > 0 {
found = true
var err = fn(match, &value)
tag := field.Tag.Get("json")
if tag == "" {
tag = field.Name
}
if err != nil {
return fmt.Errorf("%s.%s %s", g.IndirectType().Name(), field.Name, err)
return fmt.Errorf("%s %s", tag, err)
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions lib/validation/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func textValidator(match []string, value *generic.Value) error {
if v == "" {
return nil
}
var re = regexp.MustCompile(`(?m)</?(\w).*\\?>`)
if re.MatchString(v) {
return fmt.Errorf("the text cannot contains html fields")
}
return nil
}

Expand Down

0 comments on commit 5fc3c36

Please sign in to comment.