From 6e0f06c0384bc04748f6300ab92bf940d5e950b2 Mon Sep 17 00:00:00 2001 From: Eric Chiang Date: Fri, 24 Jun 2022 19:03:47 -0700 Subject: [PATCH] css: fix class selector for elements with multiple classes --- css.go | 8 ++++++-- css_test.go | 8 ++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/css.go b/css.go index 7aaa432..6fb4cbc 100644 --- a/css.go +++ b/css.go @@ -378,8 +378,12 @@ func (s *subclassSelectorMatcher) match(n *html.Node) bool { if s.classSelector != "" { for _, a := range n.Attr { - if a.Key == "class" && a.Val == s.classSelector { - return true + if a.Key == "class" { + for _, val := range strings.Fields(a.Val) { + if val == s.classSelector { + return true + } + } } } return false diff --git a/css_test.go b/css_test.go index 17e4f6d..7fa11a4 100644 --- a/css_test.go +++ b/css_test.go @@ -139,6 +139,14 @@ func TestSelector(t *testing.T) { `
`, }, }, + { + ".foo", + `

`, + []string{ + `

`, + `
`, + }, + }, { "div.foo", `

`,