Support typed bool, int and float in shortcode params

This means that you now can do:

    {{< vidur 9KvBeKu false true 32 3.14 >}}

And the boolean and numeric values will be converted to `bool`, `int` and `float64`.

If you want these to be  strings, they must be quoted:

    {{< vidur 9KvBeKu "false" "true" "32" "3.14" >}}

Fixes #6371
This commit is contained in:
Bjørn Erik Pedersen 2019-09-29 14:51:51 +02:00
parent e073f4efb1
commit 329e88db1f
12 changed files with 202 additions and 53 deletions

View file

@ -16,22 +16,26 @@ package pageparser
import "testing"
var (
tstEOF = nti(tEOF, "")
tstLeftNoMD = nti(tLeftDelimScNoMarkup, "{{<")
tstRightNoMD = nti(tRightDelimScNoMarkup, ">}}")
tstLeftMD = nti(tLeftDelimScWithMarkup, "{{%")
tstRightMD = nti(tRightDelimScWithMarkup, "%}}")
tstSCClose = nti(tScClose, "/")
tstSC1 = nti(tScName, "sc1")
tstSC1Inline = nti(tScNameInline, "sc1.inline")
tstSC2Inline = nti(tScNameInline, "sc2.inline")
tstSC2 = nti(tScName, "sc2")
tstSC3 = nti(tScName, "sc3")
tstSCSlash = nti(tScName, "sc/sub")
tstParam1 = nti(tScParam, "param1")
tstParam2 = nti(tScParam, "param2")
tstVal = nti(tScParamVal, "Hello World")
tstText = nti(tText, "Hello World")
tstEOF = nti(tEOF, "")
tstLeftNoMD = nti(tLeftDelimScNoMarkup, "{{<")
tstRightNoMD = nti(tRightDelimScNoMarkup, ">}}")
tstLeftMD = nti(tLeftDelimScWithMarkup, "{{%")
tstRightMD = nti(tRightDelimScWithMarkup, "%}}")
tstSCClose = nti(tScClose, "/")
tstSC1 = nti(tScName, "sc1")
tstSC1Inline = nti(tScNameInline, "sc1.inline")
tstSC2Inline = nti(tScNameInline, "sc2.inline")
tstSC2 = nti(tScName, "sc2")
tstSC3 = nti(tScName, "sc3")
tstSCSlash = nti(tScName, "sc/sub")
tstParam1 = nti(tScParam, "param1")
tstParam2 = nti(tScParam, "param2")
tstParamBoolTrue = nti(tScParam, "true")
tstParamBoolFalse = nti(tScParam, "false")
tstParamInt = nti(tScParam, "32")
tstParamFloat = nti(tScParam, "3.14")
tstVal = nti(tScParamVal, "Hello World")
tstText = nti(tText, "Hello World")
)
var shortCodeLexerTests = []lexerTest{
@ -69,6 +73,12 @@ var shortCodeLexerTests = []lexerTest{
{"close with extra keyword", `{{< sc1 >}}{{< /sc1 keyword>}}`, []Item{
tstLeftNoMD, tstSC1, tstRightNoMD, tstLeftNoMD, tstSCClose, tstSC1,
nti(tError, "unclosed shortcode")}},
{"float param, positional", `{{< sc1 3.14 >}}`, []Item{
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}},
{"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{