parser/pageparser: Don't allow parameters after closing tag in shortcodes

Problem:
Previously, the following self-closing shortcode syntax was incorrectly allowed:
{{% sc / param %}}

Solution:
Only allow parameters before the self-closing tag
This commit is contained in:
Guilherme Soares 2025-01-23 17:43:38 +00:00 committed by Bjørn Erik Pedersen
parent bb7b3d3cdb
commit c939c33fd3
2 changed files with 4 additions and 0 deletions

View 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()

View 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,