smarty-php / smarty

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

strip inserts space after comments. #943

Open st19311 opened 5 months ago

st19311 commented 5 months ago
{strip}
    Test{* This is only a test! *}
    ing th
    e strip function
{/strip}

results in

Test ing the strip function

with a space after Test. Removing the comment results in the removal of the space.

Happenes in the newest smarty-version, didn't test the others.

wisskid commented 5 months ago

Seems related to https://github.com/smarty-php/smarty/issues/447 May be tricky to 'fix' as this might mean unwanted changes for others.

st19311 commented 5 months ago

Mmm I see.

Well, I used Smarty 3.1 up to now (long term app, now upgraded to PHP 8.3), and that didn't have this issue (as in, strip did indeed strip all whitespace). So it must have been introduced some time after - and yea, that definitely was an unwanted change at least for me (and the other guy in #447).

It's your call what you do, but since Smarty didn't have this issue before, it seems like a regression introduced somewhere, and anyone who has an issue with a fix has essentially become reliant on a bug ;P

It also seems to make little sense to keep this behavior, because {strip} specifically states that it removes all whitespace - and well, no, it doesn't. It keeps one in there after a comment (which shouldn't have any effect on the output to start with). Which makes the documentation wrong ;)

My workaround is to compile the smarty templates myself before passing them to smarty, removing all the comments, so I still have them in the original files, and smarty doesn't see them anymore - but you know, that's hacky as all hell ;)

wisskid commented 5 months ago

It was meant as a note to myself, no worries. Can you figure out what change/version introduced it?

wisskid commented 5 months ago

The problem seems to be identical as/related to #827 and #555, both caused by a fix in 2017/2018.