go-html/path.go
Virgil 5d13a4028b
All checks were successful
Security Scan / security (push) Successful in 8s
Test / test (push) Successful in 56s
fix(html): validate block ID parsing
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-31 19:55:44 +00:00

28 lines
654 B
Go

package html
import "strings"
// ParseBlockID extracts the slot sequence from a data-block ID.
// Usage example: slots := ParseBlockID("L-0-C-0")
// "L-0-C-0" → ['L', 'C']
func ParseBlockID(id string) []byte {
if id == "" {
return nil
}
// Valid IDs are exact sequences of "{slot}-0" segments, e.g.
// "H-0" or "L-0-C-0". Any malformed segment invalidates the whole ID.
parts := strings.Split(id, "-")
if len(parts)%2 != 0 {
return nil
}
slots := make([]byte, 0, len(parts)/2)
for i := 0; i < len(parts); i += 2 {
if len(parts[i]) != 1 || parts[i+1] != "0" {
return nil
}
slots = append(slots, parts[i][0])
}
return slots
}