Skip to content

Commit 42f47da

Browse files
committed
LibWeb: Treat '<' characters as part of the text inside <script>
When we encounter a '<' during HTML parsing, we now look ahead to see if there is a full </script> coming, otherwise we treat it as text. This makes it possible to use '<' in inline scripts. :^)
1 parent fc5067a commit 42f47da

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

Libraries/LibWeb/Parser/HTMLParser.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,26 @@ static bool parse_html_document(const StringView& html, Document& document, Pare
174174
switch (state) {
175175
case State::Free:
176176
if (ch == '<') {
177-
is_slash_tag = false;
178-
move_to_state(State::BeforeTagName);
179-
break;
177+
bool should_treat_as_text = false;
178+
if (node_stack.last().tag_name() == "script") {
179+
bool is_script_close_tag = peek(1) == '/'
180+
&& tolower(peek(2)) == 's'
181+
&& tolower(peek(3)) == 'c'
182+
&& tolower(peek(4)) == 'r'
183+
&& tolower(peek(5)) == 'i'
184+
&& tolower(peek(6)) == 'p'
185+
&& tolower(peek(7)) == 't'
186+
&& tolower(peek(8)) == '>';
187+
if (!is_script_close_tag)
188+
should_treat_as_text = true;
189+
}
190+
if (!should_treat_as_text) {
191+
is_slash_tag = false;
192+
move_to_state(State::BeforeTagName);
193+
break;
194+
}
180195
}
196+
181197
if (ch != '&') {
182198
text_buffer.append(ch);
183199
} else {
@@ -394,5 +410,4 @@ RefPtr<Document> parse_html_document(const StringView& html, const URL& url)
394410

395411
return document;
396412
}
397-
398413
}

0 commit comments

Comments
 (0)