Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What "terminating characters" will generally ensure that the subsequent javascript will be run?

Is there a sequence of characters that can be used after malformed javascript code, to ensure the subsequent script will be executed?

The idea being that we have separate divisions writing javascript code that will be placed on the same page. The "other" group are notorious for leaving bad code around. Since my code will be in the footer (via site.master), what set of characters can I use to ensure (or make it more likely) that my code will be executed?

Example

 // > "" ;  */ 
 alert("this code will always run, regardless of what happens before...");
like image 842
makerofthings7 Avatar asked Jan 18 '23 13:01

makerofthings7


1 Answers

None is defined in EcmaScript itself. A syntactically invalid program will not run at all.

In HTML, </script><script> will close the current SCRIPT and open a new one, and the failure of one SCRIPT element's content to parse does not cause other SCRIPT elements' content to fail to parse since they are distinct programs.

If the preceding content is always a line comment, as in your example, any line terminator will suffice, and the EcmaScript line terminators are

U+A     \n
U+D     \r
U+D,U+A \r\n
U+2028  Line separator
U+2029  Paragraph separator

according to section 7.3 of the spec.

like image 143
Mike Samuel Avatar answered Jan 26 '23 00:01

Mike Samuel