]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
parser/pagerparser: Fix closing shortcode error handling when repeated
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sun, 5 Oct 2025 11:19:19 +0000 (13:19 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sun, 5 Oct 2025 17:06:46 +0000 (19:06 +0200)
parser/pageparser/pagelexer_shortcode.go
parser/pageparser/pageparser_shortcode_test.go

index 535d8192c9f9f065583b7cf95ea1b0147e20f0b9..12d07cd68a359c8874980cdb37c32ce2119e5a7c 100644 (file)
@@ -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)
index 29626b6adfeade0370f36c6854a18fd57581b9e7..7d14b15e85d137f0ebb63f73730569bc71f3f486 100644 (file)
@@ -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"),