From a133393edab5aca89b60fae44e445bc527095c6a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Sun, 5 Oct 2025 13:19:19 +0200 Subject: [PATCH] parser/pagerparser: Fix closing shortcode error handling when repeated --- parser/pageparser/pagelexer_shortcode.go | 10 ++++++---- parser/pageparser/pageparser_shortcode_test.go | 5 +++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/parser/pageparser/pagelexer_shortcode.go b/parser/pageparser/pagelexer_shortcode.go index 535d8192c..12d07cd68 100644 --- a/parser/pageparser/pagelexer_shortcode.go +++ b/parser/pageparser/pagelexer_shortcode.go @@ -255,16 +255,18 @@ Loop: default: l.backup() word := string(l.input[l.start:l.pos]) - if l.closingState > 0 && !l.openShortcodes[word] { - return l.errorf("closing tag for shortcode '%s' does not match start tag", word) - } else if l.closingState > 0 { + if l.closingState > 0 { + if !l.openShortcodes[word] { + return l.errorf("closing tag for shortcode '%s' does not match start tag", word) + } l.openShortcodes[word] = false lookForEnd = true + } else { + l.openShortcodes[word] = true } l.closingState = 0 l.currShortcodeName = word - l.openShortcodes[word] = true l.elementStepNum++ if l.isInline { l.emit(tScNameInline) diff --git a/parser/pageparser/pageparser_shortcode_test.go b/parser/pageparser/pageparser_shortcode_test.go index 29626b6ad..7d14b15e8 100644 --- a/parser/pageparser/pageparser_shortcode_test.go +++ b/parser/pageparser/pageparser_shortcode_test.go @@ -27,6 +27,7 @@ var ( tstRightMD = nti(tRightDelimScWithMarkup, "%}}") tstSCClose = nti(tScClose, "/") tstSC1 = nti(tScName, "sc1") + tstSCAnother = nti(tScName, "another") tstSC1Inline = nti(tScNameInline, "sc1.inline") tstSC2Inline = nti(tScNameInline, "sc2.inline") tstSC2 = nti(tScName, "sc2") @@ -74,6 +75,10 @@ var shortCodeLexerTests = []lexerTest{ tstLeftNoMD, tstSC1, tstRightNoMD, tstLeftNoMD, tstSCClose, nti(tError, "closing tag for shortcode 'another' does not match start tag"), }, nil}, + {"close wrong, repeated", `{{< sc1 >}}{{< another >}}{{< /another >}}{{< /another >}}`, []typeText{ + tstLeftNoMD, tstSC1, tstRightNoMD, tstLeftNoMD, tstSCAnother, tstRightNoMD, tstLeftNoMD, tstSCClose, tstSCAnother, tstRightNoMD, tstLeftNoMD, tstSCClose, + nti(tError, "closing tag for shortcode 'another' does not match start tag"), + }, nil}, {"close, but no open, more", `{{< sc1 >}}{{< /sc1 >}}{{< /another >}}`, []typeText{ tstLeftNoMD, tstSC1, tstRightNoMD, tstLeftNoMD, tstSCClose, tstSC1, tstRightNoMD, tstLeftNoMD, tstSCClose, nti(tError, "closing tag for shortcode 'another' does not match start tag"), -- 2.39.5