Reduce warnings due to undefined variables in templates

- 템플릿에서 변수를 단순 참조할 경우 ?? '' 를 붙여 워닝 방지
- 함수 호출이나 복잡한 문법 안에 들어간 변수까지 처리해 주지는 않음
- 불필요한 오류 메시지를 줄여서 정말 중요한 오류를 찾기 쉽도록
This commit is contained in:
Kijin Sung 2023-01-17 00:00:34 +09:00
parent aacc7dc46e
commit 3f3f270fda
2 changed files with 45 additions and 36 deletions

View file

@ -555,6 +555,10 @@ class TemplateHandler
switch($stmt)
{
case 'cond':
if (preg_match('/^\$[\\\\\w\[\]\'":>-]+$/i', $expr))
{
$expr = "$expr ?? false";
}
$nodes[$idx - 1] .= "<?php if({$expr}){ ?>";
break;
case 'loop':
@ -779,11 +783,11 @@ class TemplateHandler
if ($filter_option)
{
$filter_option = $this->_applyEscapeOption($filter_option, $escape_option);
$var = "'<a href=\"' . {$filter_option} . '\">' . {$var} . '</a>'";
$var = "'<a href=\"' . ($filter_option) . '\">' . ($var) . '</a>'";
}
else
{
$var = "'<a href=\"' . {$var} . '\">' . {$var} . '</a>'";
$var = "'<a href=\"' . ($var) . '\">' . ($var) . '</a>'";
}
$escape_option = 'noescape';
break;
@ -1027,6 +1031,11 @@ class TemplateHandler
*/
private function _applyEscapeOption($str, $escape_option)
{
if (preg_match('/^\$[\\\\\w\[\]\'":>-]+$/i', $str))
{
$str = "$str ?? ''";
}
switch($escape_option)
{
case 'escape':