Skip to content

Commit

Permalink
Fix half-broken self-closing shortcodes
Browse files Browse the repository at this point in the history
Fixes #2498
  • Loading branch information
bep committed Sep 27, 2016
1 parent 8b0d16b commit 59df7db
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions hugolib/shortcodeparser.go
Expand Up @@ -345,6 +345,7 @@ func lexShortcodeComment(l *pagelexer) stateFunc {
}

func lexShortcodeRightDelim(l *pagelexer) stateFunc {
l.closingState = 0
l.pos += pos(len(l.currentRightShortcodeDelim()))
l.emit(l.currentRightShortcodeDelimItem())
return lexTextOutsideShortcodes
Expand Down
17 changes: 14 additions & 3 deletions hugolib/shortcodeparser_test.go
Expand Up @@ -81,6 +81,18 @@ var shortCodeLexerTests = []shortCodeLexerTest{
// issue #934
{"self-closing", `{{< sc1 />}}`, []item{
tstLeftNoMD, tstSC1, tstSCClose, tstRightNoMD, tstEOF}},
// Issue 2498
{"multiple self-closing", `{{< sc1 />}}{{< sc1 />}}`, []item{
tstLeftNoMD, tstSC1, tstSCClose, tstRightNoMD,
tstLeftNoMD, tstSC1, tstSCClose, tstRightNoMD, tstEOF}},
{"self-closing with param", `{{< sc1 param1 />}}`, []item{
tstLeftNoMD, tstSC1, tstParam1, tstSCClose, tstRightNoMD, tstEOF}},
{"multiple self-closing with param", `{{< sc1 param1 />}}{{< sc1 param1 />}}`, []item{
tstLeftNoMD, tstSC1, tstParam1, tstSCClose, tstRightNoMD,
tstLeftNoMD, tstSC1, tstParam1, tstSCClose, tstRightNoMD, tstEOF}},
{"multiple different self-closing with param", `{{< sc1 param1 />}}{{< sc2 param1 />}}`, []item{
tstLeftNoMD, tstSC1, tstParam1, tstSCClose, tstRightNoMD,
tstLeftNoMD, tstSC2, tstParam1, tstSCClose, tstRightNoMD, tstEOF}},
{"nested simple", `{{< sc1 >}}{{< sc2 >}}{{< /sc1 >}}`, []item{
tstLeftNoMD, tstSC1, tstRightNoMD,
tstLeftNoMD, tstSC2, tstRightNoMD,
Expand Down Expand Up @@ -140,11 +152,10 @@ var shortCodeLexerTests = []shortCodeLexerTest{
}

func TestShortcodeLexer(t *testing.T) {
for _, test := range shortCodeLexerTests {

for i, test := range shortCodeLexerTests {
items := collect(&test)
if !equal(items, test.items) {
t.Errorf("%s: got\n\t%v\nexpected\n\t%v", test.name, items, test.items)
t.Errorf("[%d] %s: got\n\t%v\nexpected\n\t%v", i, test.name, items, test.items)
}
}
}
Expand Down

0 comments on commit 59df7db

Please sign in to comment.