Skip to content

Commit

Permalink
publisher: Fix writeStats with quote inside quotes
Browse files Browse the repository at this point in the history
Fixes #7746
  • Loading branch information
bep committed Sep 28, 2020
1 parent 4855c18 commit 1113441
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 9 additions & 2 deletions publisher/htmlElementsCollector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions publisher/htmlElementsCollector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

1 comment on commit 1113441

@divinerites
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirm the fix. Many many thanks.

Please sign in to comment.