Skip to content
This repository was archived by the owner on Apr 13, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,14 +321,14 @@ func (d *Schema) parseSchema(documentNode interface{}, currentSchema *subSchema)
if len(patternPropertiesMap) > 0 {
currentSchema.patternProperties = make(map[string]*subSchema)
for k, v := range patternPropertiesMap {
_, err := regexp.MatchString(k, "")
re, err := regexp.Compile(k)
if err != nil {
return errors.New(formatErrorDescription(
Locale.RegexPattern(),
ErrorDetails{"pattern": k},
))
}
newSchema := &subSchema{property: k, parent: currentSchema, ref: currentSchema.ref}
newSchema := &subSchema{property: k, parent: currentSchema, ref: currentSchema.ref, patternPropertyKey: re}
err = d.parseSchema(v, newSchema)
if err != nil {
return errors.New(err.Error())
Expand Down
1 change: 1 addition & 0 deletions subSchema.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ type subSchema struct {
dependencies map[string]interface{}
additionalProperties interface{}
patternProperties map[string]*subSchema
patternPropertyKey *regexp.Regexp
propertyNames *subSchema

// validation : array
Expand Down
5 changes: 2 additions & 3 deletions validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"encoding/json"
"math/big"
"reflect"
"regexp"
"strconv"
"strings"
"unicode/utf8"
Expand Down Expand Up @@ -687,8 +686,8 @@ func (v *subSchema) validatePatternProperty(currentSubSchema *subSchema, key str

validated := false

for pk, pv := range currentSubSchema.patternProperties {
if matches, _ := regexp.MatchString(pk, key); matches {
for _, pv := range currentSubSchema.patternProperties {
if pv.patternPropertyKey != nil && pv.patternPropertyKey.MatchString(key) {
validated = true
subContext := NewJsonContext(key, context)
validationResult := pv.subValidateWithContext(value, subContext)
Expand Down
Loading