Skip to content

Commit a653148

Browse files
authored
Merge pull request #940 from fastrde/fix-schema-parsing
fix(ldap): parentheses not mandatory for MUST and MAY
2 parents 26bc551 + 2a68fc1 commit a653148

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

providers/directory/schema.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package directory
33
import (
44
"fmt"
55
"regexp"
6+
"slices"
67
"strconv"
78
"strings"
89
"time"
@@ -164,8 +165,8 @@ func parseObjectClass(input string) (*ObjectClass, error) {
164165
`(?:DESC\s+'([^']+)')?\s*` +
165166
`(?:SUP\s+(?:([\w\-]+)|\(\s*([^)]+(?:\s+'[^)]+)*)\s*\)))?\s*` +
166167
`(STRUCTURAL|ABSTRACT|AUXILIARY)?\s*` +
167-
`(?:MUST\s+\(\s*([^()]+)\s*\))?\s*` +
168-
`(?:MAY\s+\(\s*([^()]+)\s*\))?\s*` +
168+
`(?:MUST\s+\(*\s*([^()]+)\s*\)*)?\s*` +
169+
`(?:MAY\s+\(*\s*([^()]+)\s*\)*)?\s*` +
169170
`\)`)
170171
matches := re.FindStringSubmatch(input)
171172

@@ -203,6 +204,10 @@ func parseObjectClass(input string) (*ObjectClass, error) {
203204
if matches[8] != "" {
204205
c.Must = strings.Fields(strings.ReplaceAll(matches[8], "$", " "))
205206
}
207+
if i := slices.Index(c.Must, "MAY"); i != -1 {
208+
c.May = c.Must[i+1:]
209+
c.Must = c.Must[:i]
210+
}
206211
if matches[9] != "" {
207212
c.May = strings.Fields(strings.ReplaceAll(matches[9], "$", " "))
208213
}

0 commit comments

Comments
 (0)