EJS不会转义字符 [英] EJS doesn't escape characters

查看:39
本文介绍了EJS不会转义字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Node JS服务器查询MongoDB,然后将返回结果呈现给EJS模板:
res.render('graphFabric.ejs',{'iBeacons':[[beacon)]}); .
当我尝试使用以下方法从模板中恢复JSON时<%= iBeacons%> '(单引号)显示为&#39 ;例如: udid:&#39; b9407f30f5f8466eaff925556b57fe6d&#39;,
由于它破坏了我的JSON结构,因此如何解决此问题?

I have a Node JS server querying MongoDB, and then render the returns to an EJS template:
res.render('graphFabric.ejs', {'iBeacons':[(beacon)]});.
When I try to recover the JSON from my template using <%=iBeacons%> , ' (single quotes) appear as &#39; For example: udid: &#39;b9407f30f5f8466eaff925556b57fe6d&#39;,
How is it possible to fix this issue since it breaks my JSON structure?

推荐答案

摘自我正在使用的https://github.com/tj/ejs/tree/0.8.3#features :
当我本应该使用
使用<%-代码%> 的转义缓冲时,默认情况下使用<%=代码%> 转义html.
**用-替换 = 可以解决问题

Figured from https://github.com/tj/ejs/tree/0.8.3#features that I was using:
Escapes html by default with <%= code %> when I should have used
Unescaped buffering with <%- code %>
**Replacing = with - fixed the problem

这篇关于EJS不会转义字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆