From cd4f0223695efc27d6f48543f8cc309241e45276 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sat, 21 Oct 2023 00:24:14 +0200 Subject: Escape runes in class names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I cannot think of a single situation where you’d ever end up in this situation, and I also am not even sure if it’s even meant to be legal HTML. Better to be on the safe side I guess. --- formatter/formatter.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/formatter/formatter.go b/formatter/formatter.go index f5d7517..8bd1c4d 100644 --- a/formatter/formatter.go +++ b/formatter/formatter.go @@ -61,7 +61,7 @@ func printAttrs(attrs []parser.Attr) { if len(classes) > 0 { fmt.Print(" class=\"") for i, a := range classes { - fmt.Print(a.Value) + printAttrVal(a.Value) if i != len(classes)-1 { fmt.Print(" ") } else { @@ -74,18 +74,22 @@ func printAttrs(attrs []parser.Attr) { fmt.Printf(" %s", a.Key) if a.Value != "" { fmt.Print("=\"") - for _, r := range a.Value { - if v, ok := attrValueEscapes[r]; ok { - fmt.Print(v) - } else { - fmt.Printf("%c", r) - } - } + printAttrVal(a.Value) fmt.Print("\"") } } } +func printAttrVal(s string) { + for _, r := range s { + if v, ok := attrValueEscapes[r]; ok { + fmt.Print(v) + } else { + fmt.Printf("%c", r) + } + } +} + func printText(s string) { for _, r := range s { if v, ok := stringEscapes[r]; ok { -- cgit v1.2.3