fix(html): trim helper tokens
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-03 19:31:54 +00:00
parent 3375ad0b22
commit 3c64352a3b
2 changed files with 23 additions and 2 deletions

View file

@ -355,10 +355,11 @@ func joinNonEmpty(parts ...string) string {
var filtered []string
for i := range parts {
if parts[i] == "" {
part := strings.TrimSpace(parts[i])
if part == "" {
continue
}
filtered = append(filtered, parts[i])
filtered = append(filtered, part)
}
if len(filtered) == 0 {
return ""

View file

@ -275,6 +275,16 @@ func TestAriaDescribedByHelper_IgnoresEmptyIDs(t *testing.T) {
}
}
func TestAriaDescribedByHelper_IgnoresWhitespaceIDs(t *testing.T) {
ctx := NewContext()
node := AriaDescribedBy(El("input"), " ", "hint-1", "\t", "hint-2")
got := node.Render(ctx)
want := `<input aria-describedby="hint-1 hint-2">`
if got != want {
t.Errorf("AriaDescribedBy() with whitespace IDs = %q, want %q", got, want)
}
}
func TestAriaLabelledByHelper(t *testing.T) {
ctx := NewContext()
node := AriaLabelledBy(El("input"), "label-1", "label-2")
@ -452,6 +462,16 @@ func TestClassHelper_IgnoresEmptyClasses(t *testing.T) {
}
}
func TestClassHelper_IgnoresWhitespaceClasses(t *testing.T) {
ctx := NewContext()
node := Class(El("div", Raw("content")), " ", "card", "\t", "card--primary")
got := node.Render(ctx)
want := `<div class="card card--primary">content</div>`
if got != want {
t.Errorf("Class() with whitespace classes = %q, want %q", got, want)
}
}
func TestAriaHiddenHelper(t *testing.T) {
ctx := NewContext()