From 53a6210d82eaa2cff7c802df88ff08dac5e7dced Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Tue, 8 Mar 2022 20:10:19 +0100 Subject: 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 --- hugolib/page.go | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'hugolib') diff --git a/hugolib/page.go b/hugolib/page.go index 175e1fc3b..c4f30de9d 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -784,6 +784,11 @@ func (p *pageState) posFromPage(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") input = input[:offset] lineNumber := bytes.Count(input, lf) + 1 -- cgit v1.2.3