Why does <!--[removed] cause a DOM tree break on the browser?

后端 未结 2 1381
离开以前
离开以前 2020-12-02 21:11

When I see the answer to solve Level 15 of http://escape.alf.nu, I notice that . (see restrictions for contents of script elements)

Both of these problem will put a browser's HTML parser into an error parsing mode, which means they are trying to make sense of invalid syntax. What browsers will do when trying to make sense of invalid syntax is undefined behavior, which technically means that anything can happen (such as nasal demons). The de facto behavior here seems to be that browsers are agreeing on how they handle this undefined behavior, but it is undefined behavior nonetheless.

For whatever reason, this combination of syntax issues next to each other causes browsers to ignore the text later in the document.


EDIT: I have identified how the parsing error is produced by stepping through this part of the HTML5 spec.

The text content of the script (excluding whitespace) is

var a = '" data1 ) [ escape ]

We can begin parsing the text content by matching data1, which has the following rule:

data1         = < any string that doesn't contain a substring that matches not-data1 >
not-data1     = ""  

The lexer cannot proceed with with valid steps according to the grammar, so the browser must now go into error processing.

提交回复
热议问题