]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
parser/pageparser: Don't allow parameters after closing tag in shortcodes
authorGuilherme Soares <guilhermesoares1970@gmail.com>
Thu, 23 Jan 2025 17:43:38 +0000 (17:43 +0000)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 24 Jan 2025 14:31:44 +0000 (15:31 +0100)
Problem:
Previously, the following self-closing shortcode syntax was incorrectly allowed:
{{% sc / param %}}

Solution:
Only allow parameters before the self-closing tag

parser/pageparser/pagelexer_shortcode.go
parser/pageparser/pageparser_shortcode_test.go

index def2f82c7331008831f60dd8d40f4749b6e0308e..535d8192c9f9f065583b7cf95ea1b0147e20f0b9 100644 (file)
@@ -322,6 +322,7 @@ func lexInsideShortcode(l *pageLexer) stateFunc {
                }
                l.closingState++
                l.isInline = false
+               l.elementStepNum = 0
                l.emit(tScClose)
        case r == '\\':
                l.ignore()
index 327da30ee6d532ec706408c415173dbe904246f7..29626b6adfeade0370f36c6854a18fd57581b9e7 100644 (file)
@@ -126,6 +126,9 @@ var shortCodeLexerTests = []lexerTest{
        {"self-closing with param", `{{< sc1 param1 />}}`, []typeText{
                tstLeftNoMD, tstSC1, tstParam1, tstSCClose, tstRightNoMD, tstEOF,
        }, nil},
+       {"self-closing with extra keyword", `{{< sc1 / keyword>}}`, []typeText{
+               tstLeftNoMD, tstSC1, tstSCClose, nti(tError, "closing tag for shortcode 'keyword' does not match start tag"),
+       }, nil},
        {"multiple self-closing with param", `{{< sc1 param1 />}}{{< sc1 param1 />}}`, []typeText{
                tstLeftNoMD, tstSC1, tstParam1, tstSCClose, tstRightNoMD,
                tstLeftNoMD, tstSC1, tstParam1, tstSCClose, tstRightNoMD, tstEOF,