From 3c64352a3b16c852c8df0d475f056e54c9f69f4b Mon Sep 17 00:00:00 2001 From: Virgil Date: Fri, 3 Apr 2026 19:31:54 +0000 Subject: [PATCH] fix(html): trim helper tokens Co-Authored-By: Virgil --- node.go | 5 +++-- node_test.go | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/node.go b/node.go index 77ed6cf..e050720 100644 --- a/node.go +++ b/node.go @@ -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 "" diff --git a/node_test.go b/node_test.go index bad25f9..6f0e34d 100644 --- a/node_test.go +++ b/node_test.go @@ -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 := `` + 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 := `
content
` + if got != want { + t.Errorf("Class() with whitespace classes = %q, want %q", got, want) + } +} + func TestAriaHiddenHelper(t *testing.T) { ctx := NewContext()