From 14c35c8a56c4dc9a1ee0053e9ff976be7715ba99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Wed, 11 Apr 2018 22:41:48 +0200 Subject: [PATCH] Allow "*/" inside commented out shortcodes Fixes #4608 --- hugolib/shortcodeparser.go | 5 +---- hugolib/shortcodeparser_test.go | 4 +++- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/hugolib/shortcodeparser.go b/hugolib/shortcodeparser.go index 18b1454cd..c57ff9b3c 100644 --- a/hugolib/shortcodeparser.go +++ b/hugolib/shortcodeparser.go @@ -312,7 +312,7 @@ func lexShortcodeLeftDelim(l *pagelexer) stateFunc { } func lexShortcodeComment(l *pagelexer) stateFunc { - posRightComment := strings.Index(l.input[l.pos:], rightComment) + posRightComment := strings.Index(l.input[l.pos:], rightComment+l.currentRightShortcodeDelim()) if posRightComment <= 1 { return l.errorf("comment must be closed") } @@ -324,9 +324,6 @@ func lexShortcodeComment(l *pagelexer) stateFunc { l.emit(tText) l.pos += pos(len(rightComment)) l.ignore() - if !strings.HasPrefix(l.input[l.pos:], l.currentRightShortcodeDelim()) { - return l.errorf("comment ends before the right shortcode delimiter") - } l.pos += pos(len(l.currentRightShortcodeDelim())) l.emit(tText) return lexTextOutsideShortcodes diff --git a/hugolib/shortcodeparser_test.go b/hugolib/shortcodeparser_test.go index 3103fd4de..45cf69baa 100644 --- a/hugolib/shortcodeparser_test.go +++ b/hugolib/shortcodeparser_test.go @@ -145,10 +145,12 @@ var shortCodeLexerTests = []shortCodeLexerTest{ {tError, 0, "got named parameter 'param2'. Cannot mix named and positional parameters"}}}, {"commented out", `{{}}`, []item{ {tText, 0, "{{<"}, {tText, 0, " sc1 "}, {tText, 0, ">}}"}, tstEOF}}, + {"commented out, with asterisk inside", `{{}}`, []item{ + {tText, 0, "{{<"}, {tText, 0, " sc1 \"**/*.pdf\" "}, {tText, 0, ">}}"}, tstEOF}}, {"commented out, missing close", `{{}}`, []item{ {tError, 0, "comment must be closed"}}}, {"commented out, misplaced close", `{{}}*/`, []item{ - {tText, 0, "{{<"}, {tText, 0, " sc1 >}}"}, {tError, 0, "comment ends before the right shortcode delimiter"}}}, + {tError, 0, "comment must be closed"}}}, } func TestShortcodeLexer(t *testing.T) {