parser/pagerparser: Fix closing shortcode error handling when repeated

This commit is contained in:
Bjørn Erik Pedersen
2025-10-05 13:19:19 +02:00
parent 9197debbfe
commit a133393eda
2 changed files with 11 additions and 4 deletions
+5 -3
View File
@@ -255,16 +255,18 @@ Loop:
default:
l.backup()
word := string(l.input[l.start:l.pos])
if l.closingState > 0 && !l.openShortcodes[word] {
if l.closingState > 0 {
if !l.openShortcodes[word] {
return l.errorf("closing tag for shortcode '%s' does not match start tag", word)
} else if l.closingState > 0 {
}
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)
@@ -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"),