sailorproject / sailor

A Lua MVC Web Framework.
MIT License
921 stars 125 forks source link

htmlspecialchars() equivalent #162

Open d9k opened 6 years ago

d9k commented 6 years ago

I asked this question at sailor chat but no one answered.

How to html encode in sailor? For example if you want to output string variable which contains double quotes character into html tag argument value?

Example usage: <input value="<?= htmlspecialchars(myvariable) ?> " > (function must be available at templates (.lp) files)

See php documentation for similar function: http://php.net/manual/en/function.htmlspecialchars.php

max-bertinetti commented 6 years ago

Lua page are different from PHP. See this: https://keplerproject.github.io/cgilua/manual.html#templates If this knowledge let you do what you need then ok. Or try with this module: https://github.com/TiagoDanin/htmlEntities-for-lua/blob/master/README.md

d9k commented 6 years ago

@CodelessFuture, thanks a lot, but htmlEntities.encode(s) doesn't encode double quote " into &quot; as expected!

Created and issue at htmlEntities project too: https://github.com/TiagoDanin/htmlEntities-for-lua/issues/6

d9k commented 6 years ago

maintainer of htmlEntities-for-lua fixed an issue, thanks him a lot! @CodelessFuture, now the question is would sailor framework include dependency to htmlEntities? And html_encode function must be available at the templates by default, I think...

max-bertinetti commented 6 years ago

Hi. I'm having some trouble at work in this period. I think I can dedicate my time at Sailor again for the end of this month.