smarty-php / smarty

Smarty is a template engine for PHP, facilitating the separation of presentation (HTML/CSS) from application logic.
Other
2.25k stars 709 forks source link

|strip_tags:true filter does not work if the input is exactly the number 0 #890

Closed ghost closed 1 year ago

ghost commented 1 year ago

Reproduction:

$x=0;
{$x|strip_tags}

Expected: 0 Result: Empty string

The Problem was introduced in https://github.com/smarty-php/smarty/blob/master/libs/plugins/modifiercompiler.strip_tags.php when a deprecation error was fixed here https://github.com/smarty-php/smarty/commit/612bd3f657875c9a425efebcab22856e4927c5ba

The operator ? is a soft == instead of ?? which checks for hard empty.

Solution: Check for 0 or use "??", but this would similar to #882

Alterantive Solution: Check if the string even contains a "<" and then just return it, if not, then you save the whole regex.

Additional: The documenation on the true/false parameter is very unclear https://www.smarty.net/docs/en/language.modifier.strip.tags.tpl as it is hard to visualize the space when a linebreak is in the documentation, adding a sentence explaining the space or no space paradigma would help a lot.

scottchiefbaker commented 1 year ago

That code isn't easily readable. Couldn't you simplify the entire thing with something like:

$x = $params[1];
if (!is_string($x)) {
    return $x;
} else {
    return strip_tags($x);
}