0

I am writing a dynamic webpage that is compiled and dynamically loaded using a C program. I have been writing the code by using:

printf ("<p><h1>Hello world!</h1></p>\n");

I want to add jQuery to the file, so the first thing I did was was a leader back slash to all quotes:

"Text here" becomes \"Text here\"

Now this leaves two problems:

1 - In the JS file, the original code looks like this:

*(?:(['\"])((?:\\\\.|[^\\\\])*?)\\3|("+O+")|)|)"+_+"*

And after the " correction is made looks like this (this is just a sample extract of code):

*(?:(['\\"])((?:\\\\.|[^\\\\])*?)\\3|(\"+O+\")|)|)\"+_+\"*

But a lot of this code is not greyed out (as it should be as I want just the contents of the line printed so the browser knows what to do). I have added some additional \s and made it grey - this appears to work, but still produces some compiling errors.

2 - When I attempt to compile, there are characters (such as \t , \r and /) that are not recongised by the compiler - how can I ensure that these are considered part of the javascript code?

Any help with this would be greatly appreciated.

4
  • It's not really clear to me what you're asking. You're compiling your javascript with C? Your HTTP server is written in C and it's not escaping things? Commented May 17, 2013 at 11:20
  • I'm writing the program completely in C, but what I do is insert the HTML lines inside printf ("") statements. I then compile this as a CGI file and it displays like a normal webpage. Commented May 17, 2013 at 11:22
  • So you're trying to output jQuery inside of a <script> tag on a HTML page that's dynamically created with C, but when you have jQuery as a string in C, you can't get it to escape properly? Commented May 17, 2013 at 11:30
  • That's my problem yep. Think you might have summarised it better than I did! Commented May 17, 2013 at 11:38

1 Answer 1

1

You also need to escape the backslashes as well, not just the quotes, that should fix both your problems.

So your JS Code should look more like this in the end:

*(?:(['\\\"])((?:\\\\\\\\.|[^\\\\\\\\])*?)\\\\3|(\"+O+\")|)|)\"+_+\"*
Sign up to request clarification or add additional context in comments.

2 Comments

So all the \ characters need their own escape backslash?
Yes, exactly. If you want to print a backslash with a printf() you need to escape it.

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.