Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for null values in template lookups #8456

Merged
merged 3 commits into from
Oct 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/en/04_Changelogs/5.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ guide developers in preparing existing 4.x code for compatibility with 5.0.
* `<% loop %>` and `<% with %>` now only ever result in one new scope level. For example
`<% loop $Pages.Limit(5) %>{$Up.Up.Title}<% end_loop %>` must be rewritten to use just one `$Up` statement to reach
the parent scope.
* Numeric and boolean values passed to methods in templates will now preserve their type, rather than
* Numeric, boolean and null values passed to methods in templates will now preserve their type, rather than
always being cast to strings. E.g. `$Foo(true)` would previously pass a string argument `'true'` to
“Foo”, but will now pass an actual boolean.

Expand Down
13 changes: 12 additions & 1 deletion src/View/SSTemplateParser.peg
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,13 @@ class SSTemplateParser extends Parser implements TemplateParser

QuotedString: q:/['"]/ String:/ (\\\\ | \\. | [^$q\\])* / '$q'

# Null

Null: / (null)\b /i

# Booleans

Boolean: / (true|false) /i
Boolean: / (true|false)\b /i

# Integers and floats

Expand Down Expand Up @@ -438,6 +442,7 @@ class SSTemplateParser extends Parser implements TemplateParser
Argument:
:DollarMarkedLookup |
:QuotedString |
:Null |
:Boolean |
:IntegerOrFloat |
:Lookup !(< FreeString)|
Expand Down Expand Up @@ -470,6 +475,12 @@ class SSTemplateParser extends Parser implements TemplateParser
$res['php'] = "'" . str_replace("'", "\\'", $sub['String']['text']) . "'";
}

function Argument_Null(&$res, $sub)
{
$res['ArgumentMode'] = 'string';
$res['php'] = $sub['text'];
}

function Argument_Boolean(&$res, $sub)
{
$res['ArgumentMode'] = 'string';
Expand Down
Loading