From 111344113bf8c16ae45528d67ff408da15961727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Mon, 28 Sep 2020 22:17:36 +0200 Subject: [PATCH] publisher: Fix writeStats with quote inside quotes Fixes #7746 --- publisher/htmlElementsCollector.go | 11 +++++++++-- publisher/htmlElementsCollector_test.go | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/publisher/htmlElementsCollector.go b/publisher/htmlElementsCollector.go index daaefe6cf17..e2f8fd2ca24 100644 --- a/publisher/htmlElementsCollector.go +++ b/publisher/htmlElementsCollector.go @@ -67,7 +67,9 @@ type cssClassCollectorWriter struct { isCollecting bool dropValue bool - inQuote bool + + inQuote bool + quoteValue byte } func (w *cssClassCollectorWriter) Write(p []byte) (n int, err error) { @@ -165,7 +167,12 @@ func (c *cssClassCollectorWriter) startCollecting() { func (c *cssClassCollectorWriter) toggleIfQuote(b byte) { if isQuote(b) { - c.inQuote = !c.inQuote + if c.inQuote && b == c.quoteValue { + c.inQuote = false + } else if !c.inQuote { + c.inQuote = true + c.quoteValue = b + } } } diff --git a/publisher/htmlElementsCollector_test.go b/publisher/htmlElementsCollector_test.go index 24bf87c2d66..6b5ef98636a 100644 --- a/publisher/htmlElementsCollector_test.go +++ b/publisher/htmlElementsCollector_test.go @@ -87,6 +87,8 @@ func TestClassCollector(t *testing.T) { {"Alpine transition 1", `
`, f("div", "mobile:-translate-x-8 opacity-0 sm:-translate-y-8 transform", "")}, {"Vue bind", `
`, f("div", "active", "")}, + // https://github.com/gohugoio/hugo/issues/7746 + {"Apostrophe inside attribute value", `my text
`, f("a div", "missingclass", "")}, } { c.Run(test.name, func(c *qt.C) { w := newHTMLElementsCollectorWriter(newHTMLElementsCollector())