ventojs / vento

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

Fix: Convert any value to string when escaping #36

Closed wrapperup closed 9 months ago

wrapperup commented 9 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 9 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 9 months ago

Thank you!