aboutsummaryrefslogtreecommitdiff
path: root/formatter
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2023-10-21 00:24:14 +0200
committerThomas Voss <mail@thomasvoss.com> 2023-10-21 00:24:14 +0200
commitcd4f0223695efc27d6f48543f8cc309241e45276 (patch)
tree1dbde0a8f51e757e76aef16deceb57f8676a55bf /formatter
parent65183681d8fff8d629afaa3c3a51cbb3639d28aa (diff)
Escape runes in class names
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.
Diffstat (limited to 'formatter')
-rw-r--r--formatter/formatter.go20
1 files 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 {