2013-04-22 20 views
0

我想知道如何在我的視圖中,在我的Node.js項目中轉義變量。在視圖中轉義變量?

例如,我的.jade視圖文件中的#{name}似乎易受SQL注入或XSS的影響。有沒有解決這個問題的標準方法?我知道在Ruby中我會做<%= H名稱%>例如...

+0

IIRC,玉逃脫默認。 – Blender 2013-04-22 08:00:53

+0

默認是玉逃跑,如果你不想逃跑,請使用!{}。 – 2013-04-22 09:13:56

回答

0
Actually want #{} for some reason? escape it! 

p \#{something} 
now we have <p>#{something}</p> 

We can also utilize the unescaped variant !{html}, so the following will result in a literal script tag: 

- var html = "<script></script>" 
| !{html} 

https://github.com/visionmedia/jade#readme

+0

我明白了。那麼是否有任何區別(消息是一個變量): p =消息 p#{message} – Misrab 2013-04-25 00:38:19

+0

變量消息和#{message}是相同的,這取決於你在哪裏/如何使用它們。以下文章幫助我http://stackoverflow.com/questions/14709560/in-jade-why-can-i-sometimes-use-variables-as-is-and-on-other-times-have-to-encl – AberZombie 2013-04-28 07:12:03