Changeset 154242 in webkit
- Timestamp:
- Aug 17, 2013 3:46:16 PM (11 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r154241 r154242 1 2013-08-17 Antti Koivisto <antti@apple.com> 2 3 <https://webkit.org/b/119963> Use TextNodeTraversal for getting sheet text in StyleElement 4 5 Reviewed by Andreas Kling. 6 7 * dom/StyleElement.cpp: 8 (WebCore::StyleElement::process): 9 10 Use TextNodeTraversal::contentsAsString for the sheet text. The overflow check is removed as StringBuilder 11 (which is used by contentsAsString) does that itself. The behavior in case of overflow changes from empty 12 sheet to CRASH(). Thats what we do elsewhere in similar situations too (scripts for example). Continuing 13 with > 4GB of style sheet text nodes is probably not going to go well anyway. 14 1 15 2013-08-17 Antti Koivisto <antti@apple.com> 2 16 -
trunk/Source/WebCore/dom/StyleElement.cpp
r147928 r154242 31 31 #include "ScriptableDocumentParser.h" 32 32 #include "StyleSheetContents.h" 33 #include "TextNodeTraversal.h" 33 34 #include <wtf/text/StringBuilder.h> 34 35 #include <wtf/text/TextPosition.h> 35 36 36 37 namespace WebCore { 37 38 static bool isValidStyleChild(Node* node)39 {40 ASSERT(node);41 Node::NodeType nodeType = node->nodeType();42 return nodeType == Node::TEXT_NODE || nodeType == Node::CDATA_SECTION_NODE;43 }44 38 45 39 static bool isCSS(Element* element, const AtomicString& type) … … 111 105 } 112 106 113 void StyleElement::process(Element* e )107 void StyleElement::process(Element* element) 114 108 { 115 if (!e || !e->inDocument())109 if (!element || !element->inDocument()) 116 110 return; 117 111 118 unsigned resultLength = 0; 119 for (Node* c = e->firstChild(); c; c = c->nextSibling()) { 120 if (isValidStyleChild(c)) { 121 unsigned length = c->nodeValue().length(); 122 if (length > std::numeric_limits<unsigned>::max() - resultLength) { 123 createSheet(e, m_startLineNumber, ""); 124 return; 125 } 126 resultLength += length; 127 } 128 } 129 StringBuilder sheetText; 130 sheetText.reserveCapacity(resultLength); 112 String sheetText = TextNodeTraversal::contentsAsString(element); 131 113 132 for (Node* c = e->firstChild(); c; c = c->nextSibling()) { 133 if (isValidStyleChild(c)) { 134 sheetText.append(c->nodeValue()); 135 } 136 } 137 ASSERT(sheetText.length() == resultLength); 138 139 createSheet(e, m_startLineNumber, sheetText.toString()); 114 createSheet(element, m_startLineNumber, sheetText); 140 115 } 141 116
Note: See TracChangeset
for help on using the changeset viewer.