go-html/path.go
Virgil 25dc761d0b
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run
fix(html): reject unknown slots in block IDs
Co-Authored-By: Virgil <virgil@lethean.io>
2026-04-03 17:25:49 +00:00

34 lines
663 B
Go

package html
import "strings"
// path.go: ParseBlockID extracts the slot sequence from a data-block ID.
// Example: ParseBlockID("L-0-C-0") returns []byte{'L', 'C'}.
func ParseBlockID(id string) []byte {
if id == "" {
return nil
}
// Split on "-" and require the exact structural pattern:
// slot, 0, slot, 0, ...
var slots []byte
i := 0
for part := range strings.SplitSeq(id, "-") {
if i%2 == 0 {
if len(part) != 1 {
return nil
}
if _, ok := slotRegistry[part[0]]; !ok {
return nil
}
slots = append(slots, part[0])
} else if part != "0" {
return nil
}
i++
}
if i == 0 || i%2 != 0 {
return nil
}
return slots
}