fix optional identity parsing (no idempotent)

This commit is contained in:
Fabio Bozzo
2024-10-22 14:13:12 +02:00
parent e66beb662e
commit b941b507e0

View File

@@ -25,6 +25,9 @@ func Parse(str string) (Selector, error) {
if str == "." { if str == "." {
return identity, nil return identity, nil
} }
if str == ".?" {
return Selector{segment{str: ".?", identity: true, optional: true}}, nil
}
col := 0 col := 0
var sel Selector var sel Selector
@@ -32,7 +35,7 @@ func Parse(str string) (Selector, error) {
seg := tok seg := tok
opt := strings.HasSuffix(tok, "?") opt := strings.HasSuffix(tok, "?")
if opt { if opt {
seg = tok[0 : len(tok)-1] seg = strings.TrimRight(tok, "?")
} }
switch { switch {
case seg == ".": case seg == ".":