]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
markup/goldmark: Fix attribute nilpointer
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 25 Apr 2022 08:05:55 +0000 (10:05 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 27 Apr 2022 21:53:56 +0000 (23:53 +0200)
Fixes 9819

markup/goldmark/codeblocks/integration_test.go
markup/goldmark/convert.go
markup/goldmark/internal/extensions/attributes/attributes.go

index 63b841e729cc6bf0c085e3110deeb030e9849b34..1990497892d2dfda1b8e2ad8f9540c6daf25b4b4 100644 (file)
@@ -302,3 +302,51 @@ Attributes: {{ .Attributes }}|Options: {{ .Options }}|
        testLanguage("bash", "Attributes: map[]|Options: map[style:monokai]|")
        testLanguage("hugo", "Attributes: map[style:monokai]|Options: map[]|")
 }
+
+func TestPanics(t *testing.T) {
+
+       files := `
+-- config.toml --
+[markup]
+[markup.goldmark]
+[markup.goldmark.parser]
+autoHeadingID = true
+autoHeadingIDType = "github"
+[markup.goldmark.parser.attribute]
+block = true
+title = true
+-- content/p1.md --
+---
+title: "p1"
+---
+
+BLOCK
+
+Common
+
+-- layouts/_default/single.html --
+{{ .Content }}
+
+
+`
+
+       for _, test := range []struct {
+               name     string
+               markdown string
+       }{
+               {"issue-9819", "asdf\n: {#myid}"},
+       } {
+               t.Run(test.name, func(t *testing.T) {
+                       t.Parallel()
+                       b := hugolib.NewIntegrationTestBuilder(
+                               hugolib.IntegrationTestConfig{
+                                       T:           t,
+                                       TxtarString: strings.ReplaceAll(files, "BLOCK", test.markdown),
+                               },
+                       ).Build()
+
+                       b.AssertFileContent("public/p1/index.html", "Common")
+               })
+       }
+
+}
index 9442ee9e7ac101d1253fb046d0c976bdbf6e0afd..ba85831b02904837a37731871703b4bef779b705 100644 (file)
@@ -16,9 +16,6 @@ package goldmark
 
 import (
        "bytes"
-       "fmt"
-       "path/filepath"
-       "runtime/debug"
 
        "github.com/gohugoio/hugo/markup/goldmark/codeblocks"
        "github.com/gohugoio/hugo/markup/goldmark/internal/extensions/attributes"
@@ -26,11 +23,6 @@ import (
 
        "github.com/gohugoio/hugo/identity"
 
-       "github.com/pkg/errors"
-
-       "github.com/spf13/afero"
-
-       "github.com/gohugoio/hugo/hugofs"
        "github.com/gohugoio/hugo/markup/converter"
        "github.com/gohugoio/hugo/markup/tableofcontents"
        "github.com/yuin/goldmark"
@@ -178,16 +170,6 @@ func (c converterResult) GetIdentities() identity.Identities {
 var converterIdentity = identity.KeyValueIdentity{Key: "goldmark", Value: "converter"}
 
 func (c *goldmarkConverter) Convert(ctx converter.RenderContext) (result converter.Result, err error) {
-       defer func() {
-               if r := recover(); r != nil {
-                       dir := afero.GetTempDir(hugofs.Os, "hugo_bugs")
-                       name := fmt.Sprintf("goldmark_%s.txt", c.ctx.DocumentID)
-                       filename := filepath.Join(dir, name)
-                       afero.WriteFile(hugofs.Os, filename, ctx.Src, 07555)
-                       fmt.Print(string(debug.Stack()))
-                       err = errors.Errorf("[BUG] goldmark: %s: create an issue on GitHub attaching the file in: %s", r, filename)
-               }
-       }()
 
        buf := &render.BufWriter{Buffer: &bytes.Buffer{}}
        result = buf
index 22c717b94e94105dbd77e448d831e455dea2d094..60ae609ec6418f831133430e4b6974208e09a681 100644 (file)
@@ -101,7 +101,7 @@ func (a *transformer) Transform(node *ast.Document, reader text.Reader, pc parse
                        // Attributes for fenced code blocks are handled in their own extension,
                        // but note that we currently only support code block attributes when
                        // CodeFences=true.
-                       if node.PreviousSibling().Kind() != ast.KindFencedCodeBlock && !node.HasBlankPreviousLines() {
+                       if node.PreviousSibling() != nil && node.PreviousSibling().Kind() != ast.KindFencedCodeBlock && !node.HasBlankPreviousLines() {
                                attributes = append(attributes, node)
                                return ast.WalkSkipChildren, nil
                        }