summaryrefslogtreecommitdiff
path: root/Libraries/LibHTML/DOM
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-10-17 23:54:27 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-10-17 23:54:27 +0200
commit6202a0ab323c02150a2f265f6b46395d4455a1c7 (patch)
tree7558d743164b0ebd9076a6416c055553b5b06211 /Libraries/LibHTML/DOM
parent9ac7b6fad1e02423f178ee1ee7074a08817769fb (diff)
downloadserenity-6202a0ab323c02150a2f265f6b46395d4455a1c7.zip
LibHTML: Only accumulate Text children's content in inline stylesheets
Some inline stylesheets use HTML comments like "<!--blah blah-->". The HTML parser currently generates a comment child node of the <style> element whenever this happens, and we don't want the comment itself to be interpreted as part of the stylesheet.
Diffstat (limited to 'Libraries/LibHTML/DOM')
-rw-r--r--Libraries/LibHTML/DOM/HTMLStyleElement.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/Libraries/LibHTML/DOM/HTMLStyleElement.cpp b/Libraries/LibHTML/DOM/HTMLStyleElement.cpp
index d527b58dcf..e4f71012b8 100644
--- a/Libraries/LibHTML/DOM/HTMLStyleElement.cpp
+++ b/Libraries/LibHTML/DOM/HTMLStyleElement.cpp
@@ -1,5 +1,7 @@
+#include <AK/StringBuilder.h>
#include <LibHTML/DOM/Document.h>
#include <LibHTML/DOM/HTMLStyleElement.h>
+#include <LibHTML/DOM/Text.h>
#include <LibHTML/Parser/CSSParser.h>
HTMLStyleElement::HTMLStyleElement(Document& document, const String& tag_name)
@@ -13,7 +15,12 @@ HTMLStyleElement::~HTMLStyleElement()
void HTMLStyleElement::inserted_into(Node& new_parent)
{
- m_stylesheet = parse_css(text_content());
+ StringBuilder builder;
+ for_each_child([&](auto& child) {
+ if (is<Text>(child))
+ builder.append(to<Text>(child).text_content());
+ });
+ m_stylesheet = parse_css(builder.to_string());
if (m_stylesheet)
document().add_sheet(*m_stylesheet);
HTMLElement::inserted_into(new_parent);