Skip to content

Commit

Permalink
Prevent minifier from removing quoutes around post-processed attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Aug 19, 2021
1 parent 3f38c78 commit 3c30fb4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 7 additions & 0 deletions hugolib/resource_chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,10 @@ func TestResourceChainPostProcess(t *testing.T) {

b := newTestSitesBuilder(t)
b.WithConfigFile("toml", `[minify]
minifyOutput = true
[minify.tdewolff]
[minify.tdewolff.html]
keepQuotes = false
keepWhitespace = false`)
b.WithContent("page1.md", "---\ntitle: Page1\n---")
b.WithContent("page2.md", "---\ntitle: Page2\n---")
Expand All @@ -473,6 +475,9 @@ HELLO: {{ $hello.RelPermalink }}
HELLO: {{ $hello.RelPermalink }}|Integrity: {{ $hello.Data.Integrity }}|MediaType: {{ $hello.MediaType.Type }}
HELLO2: Name: {{ $hello.Name }}|Content: {{ $hello.Content }}|Title: {{ $hello.Title }}|ResourceType: {{ $hello.ResourceType }}
// Issue #8884
<a href="hugo.rocks">foo</a>
<a href="{{ $hello.RelPermalink }}" integrity="{{ $hello.Data.Integrity}}">Hello</a>
`+strings.Repeat("a b", rnd.Intn(10)+1)+`
Expand All @@ -484,6 +489,8 @@ End.`)
`Start.
HELLO: /hello.min.a2d1cb24f24b322a7dad520414c523e9.html|Integrity: md5-otHLJPJLMip9rVIEFMUj6Q==|MediaType: text/html
HELLO2: Name: hello.html|Content: <h1>Hello World!</h1>|Title: hello.html|ResourceType: text
<a href=hugo.rocks>foo</a>
<a href="/hello.min.a2d1cb24f24b322a7dad520414c523e9.html" integrity="md5-otHLJPJLMip9rVIEFMUj6Q==">Hello</a>
End.`)

b.AssertFileContent("public/page1/index.html", `HELLO: /hello.min.a2d1cb24f24b322a7dad520414c523e9.html`)
Expand Down
6 changes: 5 additions & 1 deletion resources/postpub/postpub.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ type PostPublishedResource interface {

const (
PostProcessPrefix = "__h_pp_l1"
PostProcessSuffix = "__e"

// The suffix has an '=' in it to prevent the minifier to remove any enclosing
// quoutes around the attribute values.
// See issue #8884.
PostProcessSuffix = "__e="
)

func NewPostPublishResource(id int, r resource.Resource) PostPublishedResource {
Expand Down

0 comments on commit 3c30fb4

Please sign in to comment.