markup/goldmark: Fix data race in the hugocontext wrapper - hugo - [fork] hugo port for 9front
HTML git clone git@git.drkhsh.at/hugo.git
DIR Log
DIR Files
DIR Refs
DIR Submodules
DIR README
DIR LICENSE
---
DIR commit 509ab08c1b140de421c376235faa566f87ea666e
DIR parent 2d75f539e14858a7b28484b2ad1f72db284892cb
HTML Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Date: Mon, 22 Apr 2024 18:12:49 +0200
markup/goldmark: Fix data race in the hugocontext wrapper
The window for this to happen is very small, but it has been reported by Go's race detector (-race flag) in a tests once.
Diffstat:
M hugolib/page__per_output.go | 2 +-
M markup/goldmark/hugocontext/hugoco… | 4 ++--
M markup/goldmark/hugocontext/hugoco… | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
---
DIR diff --git a/hugolib/page__per_output.go b/hugolib/page__per_output.go
@@ -175,7 +175,7 @@ func (pco *pageContentOutput) RenderShortcodes(ctx context.Context) (template.HT
// This content will be parsed and rendered by Goldmark.
// Wrap it in a special Hugo markup to assign the correct Page from
// the stack.
- c = hugocontext.Wrap(c, pco.po.p.pid)
+ return template.HTML(hugocontext.Wrap(c, pco.po.p.pid)), nil
}
return helpers.BytesToHTML(c), nil
DIR diff --git a/markup/goldmark/hugocontext/hugocontext.go b/markup/goldmark/hugocontext/hugocontext.go
@@ -34,7 +34,7 @@ func New() goldmark.Extender {
// Wrap wraps the given byte slice in a Hugo context that used to determine the correct Page
// in .RenderShortcodes.
-func Wrap(b []byte, pid uint64) []byte {
+func Wrap(b []byte, pid uint64) string {
buf := bufferpool.GetBuffer()
defer bufferpool.PutBuffer(buf)
buf.Write(prefix)
@@ -45,7 +45,7 @@ func Wrap(b []byte, pid uint64) []byte {
buf.Write(b)
buf.Write(prefix)
buf.Write(closingDelimAndNewline)
- return buf.Bytes()
+ return buf.String()
}
var kindHugoContext = ast.NewNodeKind("HugoContext")
DIR diff --git a/markup/goldmark/hugocontext/hugocontext_test.go b/markup/goldmark/hugocontext/hugocontext_test.go
@@ -24,7 +24,7 @@ func TestWrap(t *testing.T) {
b := []byte("test")
- c.Assert(string(Wrap(b, 42)), qt.Equals, "{{__hugo_ctx pid=42}}\ntest{{__hugo_ctx/}}\n")
+ c.Assert(Wrap(b, 42), qt.Equals, "{{__hugo_ctx pid=42}}\ntest{{__hugo_ctx/}}\n")
}
func BenchmarkWrap(b *testing.B) {