summaryrefslogtreecommitdiffstats
path: root/markup
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-03-08 20:10:19 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-03-08 21:50:21 +0100
commit53a6210d82eaa2cff7c802df88ff08dac5e7dced (patch)
treebc393f3dc7646e7200e2a03f6e54aa474ce836fe /markup
parent7182809d96a1decf937074556ef9f6370b145c4f (diff)
markup/goldmark/codeblocks: Fix slice bounds out of range
For the Position in code blocks we try to match the .Inner with the original source. This isn't always possible. This commits avoids panics in these situations. Fixes #9627
Diffstat (limited to 'markup')
-rw-r--r--markup/goldmark/codeblocks/integration_test.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/markup/goldmark/codeblocks/integration_test.go b/markup/goldmark/codeblocks/integration_test.go
index 1a70b0bf0..7362ef297 100644
--- a/markup/goldmark/codeblocks/integration_test.go
+++ b/markup/goldmark/codeblocks/integration_test.go
@@ -164,6 +164,43 @@ fmt.Println("Hello, World!");
)
}
+func TestCodeblocksBugs(t *testing.T) {
+ t.Parallel()
+
+ files := `
+-- config.toml --
+-- layouts/_default/_markup/render-codeblock.html --
+{{ .Position | safeHTML }}
+-- layouts/_default/single.html --
+{{ .Content }}
+-- content/p1.md --
+---
+title: "p1"
+---
+
+## Issue 9627
+
+§§§text
+{{</* foo */>}}
+§§§
+
+`
+
+ b := hugolib.NewIntegrationTestBuilder(
+ hugolib.IntegrationTestConfig{
+ T: t,
+ TxtarString: files,
+ NeedsOsFS: false,
+ },
+ ).Build()
+
+ b.AssertFileContent("public/p1/index.html", `
+# Issue 9627: For the Position in code blocks we try to match the .Inner with the original source. This isn't always possible.
+p1.md:0:0
+ `,
+ )
+}
+
func TestCodeChomp(t *testing.T) {
t.Parallel()