fix: validate block id slot letters
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-04 02:13:31 +00:00
parent 2a16ce6717
commit 18765404ef
2 changed files with 9 additions and 4 deletions

View file

@ -2,7 +2,7 @@ package html
import "strings"
// path.go: ParseBlockID extracts the slot sequence from a data-block ID.
// path.go: ParseBlockID extracts the HLCRF slot sequence from a data-block ID.
// Example: ParseBlockID("L-0-C-0") returns []byte{'L', 'C'}.
func ParseBlockID(id string) []byte {
if id == "" {
@ -18,7 +18,12 @@ func ParseBlockID(id string) []byte {
if len(part) != 1 {
return nil
}
slots = append(slots, part[0])
switch part[0] {
case 'H', 'L', 'C', 'R', 'F':
slots = append(slots, part[0])
default:
return nil
}
} else {
if part == "" {
return nil

View file

@ -178,8 +178,8 @@ func TestParseBlockID(t *testing.T) {
{"C-0-C-1", []byte{'C', 'C'}},
{"H-0", []byte{'H'}},
{"C-0-C-0-C-0", []byte{'C', 'C', 'C'}},
{"X-0", []byte{'X'}},
{"H-0-X-0", []byte{'H', 'X'}},
{"X-0", nil},
{"H-0-X-0", nil},
{"", nil},
{"L-1-C-0", []byte{'L', 'C'}},
{"L-0-C", nil},