Closed colemanw closed 1 year ago
Could this be simplified to return "";
?
Could this be simplified to
return "";
?
No because '0'
is also empty()
.
Ah good point.
As far as I can see there is no benefit to escaping integers either, and I'm not sure how the various escape functions that expect a string will cope with an integer (if not currently, maybe in the future they would thrown an e-notice?) so IMO this could be further improved as
if (empty($string) || is_int($string)) {
return (string) $string;
}
But I didn't do that because this is a legacy project so I went for the minimal patch.
Smarty v2 really isn't supported anymore. Don't run it in production, it probably has a bunch of security issues.
A
null
value will cause e-notices in most of the esc_types. Functions likehtmlspecialchars
,str_replace
,preg_replace
etc do not strictly allownull
as an argument. Using an early-return if the value isempty()
should also give a subtle performance boost, as none of the esc_types do anything meaningful to empty strings or the number 0.