1

Is it possible to prevent javascript in executing \n from string.

I have string which contains \n (i.e. "ksqOOEe+sqQwexx12lMf31V\nLqW23ds"). This is encrypted string and I have to handle it in Javascript. Problem is that JS break it into two rowns, than browser register Illegal operation. I don't want to escape it with other special characters because it is encrypted string and I have to use decryption process for data reconstruction in next steps.

4
  • 3
    Javascript wouldn't parse out that \n unless you were eval() or otherwise executing the line - how is this string getting sent to JS? Commented May 31, 2012 at 15:54
  • no I can't... As I said I need to do decryption operation on that string later in process flow... Commented May 31, 2012 at 15:54
  • @MarcB I call web service with Ajax request, and than just put it into element ($.html("<div id="xx" data-id="'+ajaxResponse.encrypted+'">'+ajaxResponse.name+'</div>"); Commented May 31, 2012 at 15:57
  • Unless you can guarantee that this encrypted string won't contain " or ' characters, you'll have to escape it, or set the data-id separately so you're not passing the raw string through jquery's HTML parser. Commented May 31, 2012 at 16:02

2 Answers 2

2

Escape the slash so it doesn't see it as an escape sequence. Doing this will tell javascript that it's a literal slash, not store two slashes in the string.

Sign up to request clarification or add additional context in comments.

Comments

0

Since I'm using web service and generate encrypted string on Java side, I used URLEncoder to encode it before returning it to the client. Than on next request which contains the same encoded string, I decode it with URLDecoder and than with base64 decoder... It works, and thanks everyone for help :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.