mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-29 07:00:31 +03:00
Allow raw string literals in shortcode params
This commit is contained in:
parent
0c0bb37285
commit
da81455656
2 changed files with 62 additions and 7 deletions
|
@ -13,7 +13,9 @@
|
|||
|
||||
package pageparser
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
var (
|
||||
tstEOF = nti(tEOF, "")
|
||||
|
@ -77,13 +79,16 @@ var shortCodeLexerTests = []lexerTest{
|
|||
tstLeftNoMD, tstSC1, nti(tScParam, "3.14"), tstRightNoMD, tstEOF}},
|
||||
{"float param, named", `{{< sc1 param1=3.14 >}}`, []Item{
|
||||
tstLeftNoMD, tstSC1, tstParam1, nti(tScParamVal, "3.14"), tstRightNoMD, tstEOF}},
|
||||
{"named param, raw string", `{{< sc1 param1=` + "`" + "Hello World" + "`" + " >}}", []Item{
|
||||
tstLeftNoMD, tstSC1, tstParam1, nti(tScParamVal, "Hello World"), tstRightNoMD, tstEOF}},
|
||||
{"float param, named, space before", `{{< sc1 param1= 3.14 >}}`, []Item{
|
||||
tstLeftNoMD, tstSC1, tstParam1, nti(tScParamVal, "3.14"), tstRightNoMD, tstEOF}},
|
||||
{"Youtube id", `{{< sc1 -ziL-Q_456igdO-4 >}}`, []Item{
|
||||
tstLeftNoMD, tstSC1, nti(tScParam, "-ziL-Q_456igdO-4"), tstRightNoMD, tstEOF}},
|
||||
{"non-alphanumerics param quoted", `{{< sc1 "-ziL-.%QigdO-4" >}}`, []Item{
|
||||
tstLeftNoMD, tstSC1, nti(tScParam, "-ziL-.%QigdO-4"), tstRightNoMD, tstEOF}},
|
||||
|
||||
{"raw string", `{{< sc1` + "`" + "Hello World" + "`" + ` >}}`, []Item{
|
||||
tstLeftNoMD, tstSC1, nti(tScParam, "Hello World"), tstRightNoMD, tstEOF}},
|
||||
{"two params", `{{< sc1 param1 param2 >}}`, []Item{
|
||||
tstLeftNoMD, tstSC1, tstParam1, tstParam2, tstRightNoMD, tstEOF}},
|
||||
// issue #934
|
||||
|
@ -137,11 +142,24 @@ var shortCodeLexerTests = []lexerTest{
|
|||
{"escaped quotes inside nonescaped quotes in positional param",
|
||||
`{{< sc1 "Hello \"escaped\" World" >}}`, []Item{
|
||||
tstLeftNoMD, tstSC1, nti(tScParam, `Hello "escaped" World`), tstRightNoMD, tstEOF}},
|
||||
{"escaped raw string, named param", `{{< sc1 param1=` + `\` + "`" + "Hello World" + `\` + "`" + ` >}}`, []Item{
|
||||
tstLeftNoMD, tstSC1, tstParam1, nti(tError, "unrecognized escape character")}},
|
||||
{"escaped raw string, positional param", `{{< sc1 param1 ` + `\` + "`" + "Hello World" + `\` + "`" + ` >}}`, []Item{
|
||||
tstLeftNoMD, tstSC1, tstParam1, nti(tError, "unrecognized escape character")}},
|
||||
{"two raw string params", `{{< sc1` + "`" + "Hello World" + "`" + "`" + "Second Param" + "`" + ` >}}`, []Item{
|
||||
tstLeftNoMD, tstSC1, nti(tScParam, "Hello World"), nti(tScParam, "Second Param"), tstRightNoMD, tstEOF}},
|
||||
{"unterminated quote", `{{< sc1 param2="Hello World>}}`, []Item{
|
||||
tstLeftNoMD, tstSC1, tstParam2, nti(tError, "unterminated quoted string in shortcode parameter-argument: 'Hello World>}}'")}},
|
||||
{"unterminated raw string", `{{< sc1` + "`" + "Hello World" + ` >}}`, []Item{
|
||||
tstLeftNoMD, tstSC1, nti(tError, "unterminated raw string in shortcode parameter-argument: 'Hello World >}}'")}},
|
||||
{"unterminated raw string in second argument", `{{< sc1` + "`" + "Hello World" + "`" + "`" + "Second Param" + ` >}}`, []Item{
|
||||
tstLeftNoMD, tstSC1, nti(tScParam, "Hello World"), nti(tError, "unterminated raw string in shortcode parameter-argument: 'Second Param >}}'")}},
|
||||
{"one named param, one not", `{{< sc1 param1="Hello World" p2 >}}`, []Item{
|
||||
tstLeftNoMD, tstSC1, tstParam1, tstVal,
|
||||
nti(tError, "got positional parameter 'p2'. Cannot mix named and positional parameters")}},
|
||||
{"one named param, one quoted positional param, both raw strings", `{{< sc1 param1=` + "`" + "Hello World" + "`" + "`" + "Second Param" + "`" + ` >}}`, []Item{
|
||||
tstLeftNoMD, tstSC1, tstParam1, tstVal,
|
||||
nti(tError, "got quoted positional parameter. Cannot mix named and positional parameters")}},
|
||||
{"one named param, one quoted positional param", `{{< sc1 param1="Hello World" "And Universe" >}}`, []Item{
|
||||
tstLeftNoMD, tstSC1, tstParam1, tstVal,
|
||||
nti(tError, "got quoted positional parameter. Cannot mix named and positional parameters")}},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue