Explicitly treat null as an empty string when interpolating.
Fixes a deprecation warning on PHP 8.1+, and saves us some unnecessary escaping calls! Thanks for your help @scr4bble :) Fixes #383
This commit is contained in:
@@ -506,7 +506,7 @@ class Mustache_Compiler
|
|||||||
|
|
||||||
const VARIABLE = '
|
const VARIABLE = '
|
||||||
$value = $this->resolveValue($context->%s(%s), $context);%s
|
$value = $this->resolveValue($context->%s(%s), $context);%s
|
||||||
$buffer .= %s%s;
|
$buffer .= %s($value === null ? \'\' : %s);
|
||||||
';
|
';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ class Mustache_Test_CompilerTest extends PHPUnit_Framework_TestCase
|
|||||||
array(
|
array(
|
||||||
"\nclass Monkey extends Mustache_Template",
|
"\nclass Monkey extends Mustache_Template",
|
||||||
'$value = $this->resolveValue($context->find(\'name\'), $context);',
|
'$value = $this->resolveValue($context->find(\'name\'), $context);',
|
||||||
'$buffer .= $indent . call_user_func($this->mustache->getEscape(), $value);',
|
'$buffer .= $indent . ($value === null ? \'\' : call_user_func($this->mustache->getEscape(), $value));',
|
||||||
'return $buffer;',
|
'return $buffer;',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -76,7 +76,7 @@ class Mustache_Test_CompilerTest extends PHPUnit_Framework_TestCase
|
|||||||
array(
|
array(
|
||||||
"\nclass Monkey extends Mustache_Template",
|
"\nclass Monkey extends Mustache_Template",
|
||||||
'$value = $this->resolveValue($context->find(\'name\'), $context);',
|
'$value = $this->resolveValue($context->find(\'name\'), $context);',
|
||||||
'$buffer .= $indent . htmlspecialchars($value, ' . ENT_COMPAT . ', \'ISO-8859-1\');',
|
'$buffer .= $indent . ($value === null ? \'\' : htmlspecialchars($value, ' . ENT_COMPAT . ', \'ISO-8859-1\'));',
|
||||||
'return $buffer;',
|
'return $buffer;',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -96,7 +96,7 @@ class Mustache_Test_CompilerTest extends PHPUnit_Framework_TestCase
|
|||||||
array(
|
array(
|
||||||
"\nclass Monkey extends Mustache_Template",
|
"\nclass Monkey extends Mustache_Template",
|
||||||
'$value = $this->resolveValue($context->find(\'name\'), $context);',
|
'$value = $this->resolveValue($context->find(\'name\'), $context);',
|
||||||
'$buffer .= $indent . htmlspecialchars($value, ' . ENT_QUOTES . ', \'ISO-8859-1\');',
|
'$buffer .= $indent . ($value === null ? \'\' : htmlspecialchars($value, ' . ENT_QUOTES . ', \'ISO-8859-1\'));',
|
||||||
'return $buffer;',
|
'return $buffer;',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -123,7 +123,7 @@ class Mustache_Test_CompilerTest extends PHPUnit_Framework_TestCase
|
|||||||
"\nclass Monkey extends Mustache_Template",
|
"\nclass Monkey extends Mustache_Template",
|
||||||
"\$buffer .= \$indent . 'foo\n';",
|
"\$buffer .= \$indent . 'foo\n';",
|
||||||
'$value = $this->resolveValue($context->find(\'name\'), $context);',
|
'$value = $this->resolveValue($context->find(\'name\'), $context);',
|
||||||
'$buffer .= htmlspecialchars($value, ' . ENT_COMPAT . ', \'UTF-8\');',
|
'$buffer .= ($value === null ? \'\' : htmlspecialchars($value, ' . ENT_COMPAT . ', \'UTF-8\'));',
|
||||||
'$value = $this->resolveValue($context->last(), $context);',
|
'$value = $this->resolveValue($context->last(), $context);',
|
||||||
'$buffer .= \'\\\'bar\\\'\';',
|
'$buffer .= \'\\\'bar\\\'\';',
|
||||||
'return $buffer;',
|
'return $buffer;',
|
||||||
|
|||||||
Reference in New Issue
Block a user