mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-29 09:12:10 -05:00
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
This commit is contained in:
parent
7182809d96
commit
53a6210d82
2 changed files with 42 additions and 0 deletions
|
@ -784,6 +784,11 @@ func (p *pageState) posFromPage(offset int) text.Position {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *pageState) posFromInput(input []byte, offset int) text.Position {
|
func (p *pageState) posFromInput(input []byte, offset int) text.Position {
|
||||||
|
if offset < 0 {
|
||||||
|
return text.Position{
|
||||||
|
Filename: p.pathOrTitle(),
|
||||||
|
}
|
||||||
|
}
|
||||||
lf := []byte("\n")
|
lf := []byte("\n")
|
||||||
input = input[:offset]
|
input = input[:offset]
|
||||||
lineNumber := bytes.Count(input, lf) + 1
|
lineNumber := bytes.Count(input, lf) + 1
|
||||||
|
|
|
@ -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) {
|
func TestCodeChomp(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue