ventojs / vento

🌬 A template engine for Deno & Node
https://vento.js.org/
MIT License
153 stars 9 forks source link

Fix: Convert any value to string when escaping #36

Closed wrapperup closed 4 months ago

wrapperup commented 4 months ago

Ran into this issue when using autoescape (but this also affects escaping values in general). This ensures any value that is passed into the filter is converted into a string. html.escape expects a string input, it doesn't convert the value automatically for you.

For example, this wouldn't work:

const env = vento({
  autoescape: true
});

const res = env.run("my-template.vto", { number: 10 });
  Error: Error in the template my-template.vto:11:5

  {{ number }}

  > str.replaceAll is not a function
oscarotero commented 4 months ago

Great. Can you run deno fmt to fix formatting issues? Also, it would be nice to add a test for that (in /test/escape.test.ts and /test/unescape.test.ts). Thanks!

oscarotero commented 4 months ago

Thank you!