From de37455ec73cffd039b44e8f6c62d2884b1d6bbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Thu, 28 Jun 2018 16:06:16 +0200 Subject: [PATCH] hugolib: Allow forward slash in shortcode names Fixes #4886 --- hugolib/shortcodeparser.go | 2 ++ hugolib/shortcodeparser_test.go | 3 +++ 2 files changed, 5 insertions(+) diff --git a/hugolib/shortcodeparser.go b/hugolib/shortcodeparser.go index c57ff9b3c..32aa8b47a 100644 --- a/hugolib/shortcodeparser.go +++ b/hugolib/shortcodeparser.go @@ -464,6 +464,8 @@ Loop: for { switch r := l.next(); { case isAlphaNumericOrHyphen(r): + // Allow forward slash inside names to make it possible to create namespaces. + case r == '/': default: l.backup() word := l.input[l.start:l.pos] diff --git a/hugolib/shortcodeparser_test.go b/hugolib/shortcodeparser_test.go index 45cf69baa..532c8e739 100644 --- a/hugolib/shortcodeparser_test.go +++ b/hugolib/shortcodeparser_test.go @@ -33,6 +33,7 @@ var ( tstSC1 = item{tScName, 0, "sc1"} tstSC2 = item{tScName, 0, "sc2"} tstSC3 = item{tScName, 0, "sc3"} + tstSCSlash = item{tScName, 0, "sc/sub"} tstParam1 = item{tScParam, 0, "param1"} tstParam2 = item{tScParam, 0, "param2"} tstVal = item{tScParamVal, 0, "Hello World"} @@ -45,6 +46,8 @@ var shortCodeLexerTests = []shortCodeLexerTest{ {"no markup", `{{< sc1 >}}`, []item{tstLeftNoMD, tstSC1, tstRightNoMD, tstEOF}}, {"with EOL", "{{< sc1 \n >}}", []item{tstLeftNoMD, tstSC1, tstRightNoMD, tstEOF}}, + {"forward slash inside name", `{{< sc/sub >}}`, []item{tstLeftNoMD, tstSCSlash, tstRightNoMD, tstEOF}}, + {"simple with markup", `{{% sc1 %}}`, []item{tstLeftMD, tstSC1, tstRightMD, tstEOF}}, {"with spaces", `{{< sc1 >}}`, []item{tstLeftNoMD, tstSC1, tstRightNoMD, tstEOF}}, {"mismatched rightDelim", `{{< sc1 %}}`, []item{tstLeftNoMD, tstSC1,