Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2016-09-27 22:11:34 +0300
committerGitHub <noreply@github.com>2016-09-27 22:11:34 +0300
commit59df7db764d011b6e082d11d4660e9c8833a3b75 (patch)
tree7229d744e253225eb7ee41f86419eb36011c2224 /hugolib
parent8b0d16b8d911026ca43057b08c9365c24e4228d8 (diff)
Fix half-broken self-closing shortcodes
Fixes #2498
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/shortcodeparser.go1
-rw-r--r--hugolib/shortcodeparser_test.go17
2 files changed, 15 insertions, 3 deletions
diff --git a/hugolib/shortcodeparser.go b/hugolib/shortcodeparser.go
index a15b057a9..027d661ca 100644
--- a/hugolib/shortcodeparser.go
+++ b/hugolib/shortcodeparser.go
@@ -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
diff --git a/hugolib/shortcodeparser_test.go b/hugolib/shortcodeparser_test.go
index a5d7453cc..662ce0f64 100644
--- a/hugolib/shortcodeparser_test.go
+++ b/hugolib/shortcodeparser_test.go
@@ -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,
@@ -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)
}
}
}