]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
markup/goldmark: Fix data race in the hugocontext wrapper
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 22 Apr 2024 16:12:49 +0000 (18:12 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 22 Apr 2024 17:10:15 +0000 (19:10 +0200)
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.

hugolib/page__per_output.go
markup/goldmark/hugocontext/hugocontext.go
markup/goldmark/hugocontext/hugocontext_test.go

index 4ff67c074bf84f8d84be883973e4ba638a265331..2adb5cbb7d7bab81b104dcbfc9cda26fcd6b3d67 100644 (file)
@@ -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
index ed62bb8c6eea06b620d33387fa52f5e5a390a51e..b9c548dac5ea7cd98c760005359aa4ac8a336d17 100644 (file)
@@ -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")
index da96cc3392bd1de181df9a5edfaa0a5596af76ea..4a6eb80f597162c6bad9d4f9f82df639509a9c3c 100644 (file)
@@ -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) {