Index: Source/core/html/parser/HTMLConstructionSite.cpp |
diff --git a/Source/core/html/parser/HTMLConstructionSite.cpp b/Source/core/html/parser/HTMLConstructionSite.cpp |
index 171d1d3e2f00e36c732e24041ad1b47d0794ea12..4cecc3db4d99c44d5206d76ed647ef166d2a9986 100644 |
--- a/Source/core/html/parser/HTMLConstructionSite.cpp |
+++ b/Source/core/html/parser/HTMLConstructionSite.cpp |
@@ -51,7 +51,8 @@ |
#include "core/page/Settings.h" |
#include "core/platform/LocalizedStrings.h" |
#include "core/platform/NotImplemented.h" |
-#include <wtf/UnusedParam.h> |
+#include "wtf/UnusedParam.h" |
+#include <limits> |
namespace WebCore { |
@@ -78,6 +79,13 @@ static bool hasImpliedEndTag(const HTMLStackItem* item) |
|| item->hasTagName(rtTag); |
} |
+static bool shouldUseLengthLimit(const ContainerNode* node) |
+{ |
+ return !node->hasTagName(scriptTag) |
+ && !node->hasTagName(styleTag) |
+ && !node->hasTagName(SVGNames::scriptTag); |
+} |
+ |
static inline bool isAllWhitespace(const String& string) |
{ |
return string.isAllSpecialCharacters<isHTMLSpace>(); |
@@ -553,6 +561,7 @@ void HTMLConstructionSite::insertTextNode(const String& characters, WhitespaceMo |
|| (whitespaceMode == WhitespaceUnknown && isAllWhitespace(characters)); |
unsigned currentPosition = 0; |
+ unsigned lengthLimit = shouldUseLengthLimit(task.parent.get()) ? Text::defaultLengthLimit : std::numeric_limits<unsigned>::max(); |
// FIXME: Splitting text nodes into smaller chunks contradicts HTML5 spec, but is currently necessary |
// for performance, see <https://bugs.webkit.org/show_bug.cgi?id=55898>. |
@@ -562,11 +571,11 @@ void HTMLConstructionSite::insertTextNode(const String& characters, WhitespaceMo |
// FIXME: We're only supposed to append to this text node if it |
// was the last text node inserted by the parser. |
CharacterData* textNode = static_cast<CharacterData*>(previousChild); |
- currentPosition = textNode->parserAppendData(characters, 0, Text::defaultLengthLimit); |
+ currentPosition = textNode->parserAppendData(characters, 0, lengthLimit); |
} |
while (currentPosition < characters.length()) { |
- RefPtr<Text> textNode = Text::createWithLengthLimit(task.parent->document(), shouldUseAtomicString ? AtomicString(characters).string() : characters, currentPosition); |
+ RefPtr<Text> textNode = Text::createWithLengthLimit(task.parent->document(), shouldUseAtomicString ? AtomicString(characters).string() : characters, currentPosition, lengthLimit); |
// If we have a whole string of unbreakable characters the above could lead to an infinite loop. Exceeding the length limit is the lesser evil. |
if (!textNode->length()) { |
String substring = characters.substring(currentPosition); |