Skip to content

Commit a133393

Browse files
committed
parser/pagerparser: Fix closing shortcode error handling when repeated
1 parent 9197deb commit a133393

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

‎parser/pageparser/pagelexer_shortcode.go‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,16 +255,18 @@ Loop:
255255
default:
256256
l.backup()
257257
word := string(l.input[l.start:l.pos])
258-
if l.closingState > 0 && !l.openShortcodes[word] {
259-
return l.errorf("closing tag for shortcode '%s' does not match start tag", word)
260-
} else if l.closingState > 0 {
258+
if l.closingState > 0 {
259+
if !l.openShortcodes[word] {
260+
return l.errorf("closing tag for shortcode '%s' does not match start tag", word)
261+
}
261262
l.openShortcodes[word] = false
262263
lookForEnd = true
264+
} else {
265+
l.openShortcodes[word] = true
263266
}
264267

265268
l.closingState = 0
266269
l.currShortcodeName = word
267-
l.openShortcodes[word] = true
268270
l.elementStepNum++
269271
if l.isInline {
270272
l.emit(tScNameInline)

‎parser/pageparser/pageparser_shortcode_test.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var (
2727
tstRightMD = nti(tRightDelimScWithMarkup, "%}}")
2828
tstSCClose = nti(tScClose, "/")
2929
tstSC1 = nti(tScName, "sc1")
30+
tstSCAnother = nti(tScName, "another")
3031
tstSC1Inline = nti(tScNameInline, "sc1.inline")
3132
tstSC2Inline = nti(tScNameInline, "sc2.inline")
3233
tstSC2 = nti(tScName, "sc2")
@@ -74,6 +75,10 @@ var shortCodeLexerTests = []lexerTest{
7475
tstLeftNoMD, tstSC1, tstRightNoMD, tstLeftNoMD, tstSCClose,
7576
nti(tError, "closing tag for shortcode 'another' does not match start tag"),
7677
}, nil},
78+
{"close wrong, repeated", `{{< sc1 >}}{{< another >}}{{< /another >}}{{< /another >}}`, []typeText{
79+
tstLeftNoMD, tstSC1, tstRightNoMD, tstLeftNoMD, tstSCAnother, tstRightNoMD, tstLeftNoMD, tstSCClose, tstSCAnother, tstRightNoMD, tstLeftNoMD, tstSCClose,
80+
nti(tError, "closing tag for shortcode 'another' does not match start tag"),
81+
}, nil},
7782
{"close, but no open, more", `{{< sc1 >}}{{< /sc1 >}}{{< /another >}}`, []typeText{
7883
tstLeftNoMD, tstSC1, tstRightNoMD, tstLeftNoMD, tstSCClose, tstSC1, tstRightNoMD, tstLeftNoMD, tstSCClose,
7984
nti(tError, "closing tag for shortcode 'another' does not match start tag"),

0 commit comments

Comments
 (0)