Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The right/best way to deal with newlines #375

Open
bertvandepoel opened this issue Aug 8, 2021 · 0 comments
Open

The right/best way to deal with newlines #375

bertvandepoel opened this issue Aug 8, 2021 · 0 comments

Comments

@bertvandepoel
Copy link

I'm pretty new at Mustache, so I might just have misunderstood, but it seems quite challenging to deal with user supplied text containing newlines.

I was somewhat surprised to find that Mustache by default performs html encoding/escaping, but not nl2br. I then thought I would simply pass my string as nl2br, but obviously that will result in the
s getting escaped themselves. Of course I could use {{{var}}} but then I lose my added security. I then looked into filters but found that $m->addHelper('nl2br', function($value) { return nl2br($value); } ); with {{var | nl2br}} would still result in escaped
. Finally I found and adapted #173 and that worked.

Now my main question is whether using $m->addHelper('nl2br', function($text, $mustache) { return nl2br($mustache->render($text)); } ); with {{#nl2br}}{{var}}{{/nl2br}} is indeed the best, cleanest and most correct option.

I was also wondering, whether the answer is that that is the best option or not, if such a case shouldn't be mentioned in the wiki documentation. I looked around quite a bit specifically for this newline situation, since I presumed most mustache.php users would come across it, before moving on to trying to write a filter myself.

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

No branches or pull requests

1 participant