Peter Whitfield
Peter Whitfield

Reputation: 525

replace escaped " with escaped ' in ruby string

I have a ruby string which includes many escaped double quotes \" that I want to replace with an escaped single quote \' but I can't work out how to do it.

I've been trying to use gsub, but something like mystring.gsub('\\"', '\\'') doesn't work.

Sample of (part of) the string below - my problem is that I don't want to replace all the double quotes, just the escaped ones...

FYI, the injected script works fine in included as src, but I'm pulling the content dynamically and injecting into the script in the view:

instead of

<script src='...'></script> 

Im doing

<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");

Can someone help?

Upvotes: 1

Views: 106

Answers (2)

Peter Whitfield
Peter Whitfield

Reputation: 525

In the end, I wound up using a prerender server to prerender the page and include the contents of the script.

I got to the point where if the script was included from src url it worked, but if I tried to pull in the source and including it in the page between tags it wouldn't work.

Using prerender allowed me to run the script on the server side and generate the page before returning completed partial to the browser.

Upvotes: 0

BroiSatse
BroiSatse

Reputation: 44685

Most likely they are not escaped. This is just the way ruby displays strings with quotes when you execute inspect on them (console execute inspect by default to display results of commands). Try:

mystring.gsub('"', "'")

Upvotes: 1

Related Questions