diff options
author | Andreas Kling <kling@serenityos.org> | 2020-04-04 21:01:58 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-04 21:01:58 +0200 |
commit | 42f47da75dbac8726091da39b69155c0982530f6 (patch) | |
tree | 93c9f18068fc8add484cef529f5248ac593f09d9 /Libraries/LibWeb | |
parent | fc5067afd287b951b07b00e39126562164f29207 (diff) | |
download | serenity-42f47da75dbac8726091da39b69155c0982530f6.zip |
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. :^)
Diffstat (limited to 'Libraries/LibWeb')
-rw-r--r-- | Libraries/LibWeb/Parser/HTMLParser.cpp | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/Libraries/LibWeb/Parser/HTMLParser.cpp b/Libraries/LibWeb/Parser/HTMLParser.cpp index c21fd30806..359121ab46 100644 --- a/Libraries/LibWeb/Parser/HTMLParser.cpp +++ b/Libraries/LibWeb/Parser/HTMLParser.cpp @@ -174,10 +174,26 @@ static bool parse_html_document(const StringView& html, Document& document, Pare switch (state) { case State::Free: if (ch == '<') { - is_slash_tag = false; - move_to_state(State::BeforeTagName); - break; + bool should_treat_as_text = false; + if (node_stack.last().tag_name() == "script") { + bool is_script_close_tag = peek(1) == '/' + && tolower(peek(2)) == 's' + && tolower(peek(3)) == 'c' + && tolower(peek(4)) == 'r' + && tolower(peek(5)) == 'i' + && tolower(peek(6)) == 'p' + && tolower(peek(7)) == 't' + && tolower(peek(8)) == '>'; + if (!is_script_close_tag) + should_treat_as_text = true; + } + if (!should_treat_as_text) { + is_slash_tag = false; + move_to_state(State::BeforeTagName); + break; + } } + if (ch != '&') { text_buffer.append(ch); } else { @@ -394,5 +410,4 @@ RefPtr<Document> parse_html_document(const StringView& html, const URL& url) return document; } - } |