Skip to content

Fix incorrect code when escape_html=true#930

Merged
wisskid merged 1 commit intosmarty-php:masterfrom
wxiaoguang:fix-escape-5.0
Feb 5, 2024
Merged

Fix incorrect code when escape_html=true#930
wisskid merged 1 commit intosmarty-php:masterfrom
wxiaoguang:fix-escape-5.0

Conversation

@wxiaoguang
Copy link
Copy Markdown
Contributor

@wxiaoguang wxiaoguang commented Jan 26, 2024

Fix #928

When setting escape_html=true, the following code:

{$foo+$bar}

becomes:

<?php echo htmlspecialchars((string) $_smarty_tpl->tpl_vars['foo']->value+$_smarty_tpl->tpl_vars['bar']->value, ENT_QUOTES, 'UTF-8');?>

The code: (string) $a + $b is not correct, it should be (string) ($a + $b).

@wxiaoguang
Copy link
Copy Markdown
Contributor Author

Hi @wisskid, is there any interest in this fix? 4.x also needs this fix IMO.

@wisskid
Copy link
Copy Markdown
Member

wisskid commented Feb 5, 2024

I think so. Can you clarify the actual error this causes?

@wxiaoguang
Copy link
Copy Markdown
Contributor Author

The function: htmlspecialchars(string $string, ....), the first argument's type is string (PHP is more and more strict about typing)

But {$foo+$bar} would result in non-string type:

$ php -r 'echo gettype( (string)1+2 );'
integer%

So, it needs to use htmlspecialchars((string) ({$output}), to make sure the type is string:

$ php -r 'echo gettype( (string)(1+2) );'
string%

@wisskid wisskid merged commit 1820e87 into smarty-php:master Feb 5, 2024
@wxiaoguang wxiaoguang deleted the fix-escape-5.0 branch February 5, 2024 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

escape_html generates incorrect php code

2 participants