我有一个ruby字符串,其中包含许多转义双引号\“我想用转义的单引号替换”但我无法弄清楚如何做到这一点 .
我一直在尝试使用gsub,但像mystring.gsub('\'','\'')这样的东西不起作用 .
以下字符串(部分)的示例 - 我的问题是我不想替换所有双引号,只是转义的...
仅供参考,注入的脚本在src中工作正常,但是我正在动态提取内容并注入视图中的脚本:
代替
<script src='...'></script>
我正在做
<script><%=raw @mystring%></script>
....
document.write("<div class=\"fsBody fsEmbed\">"+"\n");
document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"https://www.formstack.com/forms/css/3/reset.css?20140508\" />"+"\n");
document.write(" <link rel=\"stylesheet\" type=\"text/css\" href=\"https://www.formstack.com/forms/css/3/default.css?20140519\" />"+"\n");
document.write(" "+"\n");
document.write("<!--[if IE]>"+"\n");
document.write(" <link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"https://www.formstack.com/forms/css/3/ie.css?20140508\" />"+"\n");
document.write("<![endif]-->"+"\n");
document.write("<!--[if IE 7]><link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"https://www.formstack.com/forms/css/3/ie7.css\" /><![endif]-->"+"\n");
document.write("<!--[if IE 6]><link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"https://www.formstack.com/forms/css/3/ie6fixes.css\" /><![endif]-->"+"\n");
document.write(" <style type=\"text/css\">"+"\n");
document.write(" "+"\n");
document.write(" .fsBody .fsForm, .fsForm .fsSpacerRow .fsRowBody {"+"\n");
有人可以帮忙吗?
2 回答
最有可能的是他们没有逃脱 . 这就是当ruby在它们上执行
inspect
时显示带引号的字符串的方式(控制台默认执行inspect以显示命令的结果) . 尝试:最后,我结束了使用预呈现服务器来预呈现页面并包含脚本的内容 .
我已经到了如果脚本是从src url包含它有效的地方,但是如果我试图拉入源并将它包含在标签之间的页面中它将无法工作 .
使用prerender允许我在服务器端运行脚本并生成页面,然后将完成的部分返回到浏览器 .