publisher: Fix writeStats with quote inside quotes
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 28 Sep 2020 20:17:36 +0000 (22:17 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 28 Sep 2020 20:17:36 +0000 (22:17 +0200)
Fixes #7746

publisher/htmlElementsCollector.go
publisher/htmlElementsCollector_test.go

index daaefe6cf17fe2821c2be2497494cd773551805d..e2f8fd2ca241563da764aa61a507c4fb70515cb9 100644 (file)
@@ -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
+               }
        }
 }
 
index 24bf87c2d66fe61fb889eff602ae877a978e779f..6b5ef98636ab654a088390d928a2b111c68a51b4 100644 (file)
@@ -87,6 +87,8 @@ func TestClassCollector(t *testing.T) {
 
                {"Alpine transition 1", `<div x-transition:enter-start="opacity-0 transform mobile:-translate-x-8 sm:-translate-y-8">`, f("div", "mobile:-translate-x-8 opacity-0 sm:-translate-y-8 transform", "")},
                {"Vue bind", `<div v-bind:class="{ active: isActive }"></div>`, f("div", "active", "")},
+               // https://github.com/gohugoio/hugo/issues/7746
+               {"Apostrophe inside attribute value", `<a class="missingclass" title="Plus d'information">my text</a><div></div>`, f("a div", "missingclass", "")},
        } {
                c.Run(test.name, func(c *qt.C) {
                        w := newHTMLElementsCollectorWriter(newHTMLElementsCollector())