From 33e5d1ff190ef2a0b9b1db052ed4f2756fa3e8e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20R=C3=BCger?= Date: Sat, 5 Oct 2024 23:56:07 +0200 Subject: [PATCH] blockquote: Fix invalid access --- renderer/blockquote.go | 5 ++--- testdata/quotes-droph1.html | 4 ++++ testdata/quotes-stripnewlines.html | 3 +++ testdata/quotes.html | 4 ++++ testdata/quotes.md | 5 +++++ 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/renderer/blockquote.go b/renderer/blockquote.go index 12100b33..30e8fd0d 100644 --- a/renderer/blockquote.go +++ b/renderer/blockquote.go @@ -118,13 +118,12 @@ func ParseBlockQuoteType(node ast.Node, source []byte) BlockQuoteType { // Classifying the next text type node (midNode) will confirm that. if t == None { midNode := node.NextSibling() - rightNode := midNode.NextSibling() - if midNode.Kind() == ast.KindText { + if midNode != nil && midNode.Kind() == ast.KindText { + rightNode := midNode.NextSibling() midTextNode := midNode.(*ast.Text) if rightNode != nil && rightNode.Kind() == ast.KindText { rightTextNode := rightNode.(*ast.Text) - if string(n.Text(source)) == "[" && string(rightTextNode.Text(source)) == "]" { t = ghAlertsClassifier.ClassifyingBlockQuote(string(midTextNode.Text(source))) } diff --git a/testdata/quotes-droph1.html b/testdata/quotes-droph1.html index 8b98bc47..4fdba685 100644 --- a/testdata/quotes-droph1.html +++ b/testdata/quotes-droph1.html @@ -98,3 +98,7 @@

Should not

[NOTE]

+
+

TL;DR: Thingy! +More stuff

+
diff --git a/testdata/quotes-stripnewlines.html b/testdata/quotes-stripnewlines.html index ba9c9731..e07a0474 100644 --- a/testdata/quotes-stripnewlines.html +++ b/testdata/quotes-stripnewlines.html @@ -96,3 +96,6 @@

Should not

[NOTE]

+
+

TL;DR: Thingy! More stuff

+
diff --git a/testdata/quotes.html b/testdata/quotes.html index a2d2a002..15a23176 100644 --- a/testdata/quotes.html +++ b/testdata/quotes.html @@ -99,3 +99,7 @@

Should not

[NOTE]

+
+

TL;DR: Thingy! +More stuff

+
diff --git a/testdata/quotes.md b/testdata/quotes.md index d9de8e05..aeeb7c1a 100644 --- a/testdata/quotes.md +++ b/testdata/quotes.md @@ -88,3 +88,8 @@ > [Hey !NOTE] > [NOTE] + + + +> **TL;DR:** Thingy! +> More stuff