So I'm trying to work on passing a url from my backend to my frontend and it has some escaping going on such that by the time the string gets to the frontend it looks something like "www.test.com".
Is there a way I can unescape this string or is my best solution here to just manually replace substrings of " with quotes?
Thanks for your help!
'"www.test.com"'.replace(/"/g,'')
output:
"www.test.com"
Related
I have an HTMl string that is stored in a database. When I go to set the value of a javascript variable with this string on the front-end via my templating engine (Leaf), it stores escaped as:
var string = <p>It's a round about way.</p> <p><!-- pagebreak -->But Maybe this is the way?</p>;
I'm trying to set this value as the content value for TinyMCE, but JavaScript produces an Unexpected EOF error when reading this string and points to a & character, which I presume is the first character of the new line. I tried on the back-end to replace occurrences of string \r\n with a so it would play nicer with JavaScript but the changes didn't seem to take. I tried encoding/decoding the string but that didn't help. Perhaps someone can help shed some light on this seemingly trivial task?
Thanks in advance.
Javascript was rendering \r\n characters found in the string instead of escaping them. Parsed it out in the server-side code instead of handling in JS.
I'm trying to convert Chinese characters in a XML file to readable Chinese string using javascript, but I'm not sure how to. I have checked other SO posts, and tried the following
unescape(encodeURIComponent('丘'))
but still can't get it to work, and wondering if someone could help?
<utf8>丘</utf8>
Neither unescape nor encodeURIComponent (which deal with percent-encoding) will help you with a XML character entity. You just want to parse the XML file! Accessing the DOM then will yield the expected string.
one API that I have to use returns the text using ISO-88951-1, so the words with spanish accents like "obtendrá" are wrong codified when I show them to the user (the valid output would be "obtendrá").
How can I transform the text to UTF-8? I need a function in javascript or jQuery to perfom this conversion.
Thanks
There are at least a couple of modules on npm that let you do encoding conversions: iconv (requires compilation) and iconv-lite (doesn't require compilation).
Finally I achieve what I need using:
$("<div>").html(theTextinHex).text();
Thanks anyway!
I have to encode string in c# and decode it with javascript unescape function.
the javascript unescape is the only option since I am sending the string with get request to some api that using unescape to decoed it.
i tried almost everything
server.urlencode
WebUtility.HtmlEncode
and a lot other encoding! I even tried Uri.EscapeDataString using jscript
Nothing isn't encode like the "escape" function
Any idea How to make it work?
EDIT:
this is my code
string apiGetRequest = String.Format("http://212.00.00.00/Klita?name={0}&city={1}&CREATEBY=test ", Uri.EscapeDataString(name), Uri.EscapeDataString(city));
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(apiGetRequest);
req.GetResponse();
Can you give an example of the string you want do encode and the encoded result?
URLencoding is the correct encoding-type you need. Make sure, you don't double encode your string somewhere in your code.
You might need to use decodeURIComponent instead of unescape, since unescape is not UTF-8 aware, thus might result in in broken string after decoding.
See http://xkr.us/articles/javascript/encode-compare/ for more information.
EDIT:
I don't know much about asp, but it looks like your trying to access the url not with a browser but with your ASP-server-side application. Well, your server does not run any JS code. You will just retrieve the HTML markup and maybe some JS code as a big string. This code would be parsed and executed within a browser but not within ASP.
I am using asp.net mvc 3 with razor for a project.
At some I need to serialize an array from the controller, put it in the viewdata and assign it to a js object. However when I output it using
#ViewData["some array"]
The result is html escaped so i get something like :
[{"title":"Something","id":"Something-1" etc'
With the <%= %> this was not escaped so it was behaving as expected.
Is it possible to tell razor not to escape this string. Perhaps, someone might suggest another approach all together.
Thanks in advance for any ideas
You need to output an instance of the new IHtmlString interface, which contains pre-escaped HTML.
To do that write #Html.Raw(...).
If you have done everything and still issue persist while it was working earlier.. Better check Certificate Expiration Date.