diff --git a/path.go b/path.go index 3e5219b..991e909 100644 --- a/path.go +++ b/path.go @@ -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 diff --git a/path_test.go b/path_test.go index e57a1ff..81b9e63 100644 --- a/path_test.go +++ b/path_test.go @@ -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},