Skip to main content

How to replace rel value double quotes from string without having access to the HMTL?

I have an issue with a string that has double quotes (") when I get it from the backend I get it like this <span class="parsed-qr-field" rel="{ "id": 123, "sign": "45tgrl:" }"></span> and then I have to send it through an API to another machine which renders what I'm sending

So when they try to print the HTML is giving issues due to the double quotes ". Is there a way of replacing the rel attribute value in the string for this rel="{ &quot;id&quot;: 123, &quot;sign&quot;: &quot;45tgrl:&quot; }" as when we do it manually like that it works

We can not do the replaces statically as the rel values changes per every request

I have already tried to do things like:

_this._page += Template.TemplateHTML.replace(/"/g, '\\"')

Or

var doc = new DOMParser().parseFromString(Template.TemplateHTML, "text/html");
doc.querySelector('span[rel]').rel = doc.querySelector('span[rel]').rel.replace(/"/g, '&quot');
Via Active questions tagged javascript - Stack Overflow https://ift.tt/w71lyAH

Comments