Changeset 30123 in webkit
- Timestamp:
- Feb 10, 2008 12:13:51 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r30116 r30123 1 2008-02-10 Andrew Wellington <proton@wiretapped.net> 2 3 Reviewed and tweaked a bit by Darin. 4 5 DOMRange.surroundContents throws wrong exception (Acid3 bug) 6 http://bugs.webkit.org/show_bug.cgi?id=16749 7 8 Throw BAD_BOUNDARYPOINTS_ERR if attempting to split a non-text node that 9 has offsets in characters 10 11 * fast/dom/Range/range-exceptions-expected.txt: Added. 12 * fast/dom/Range/resources/range-exceptions.js: Added. 13 1 14 2008-02-09 David Hyatt <hyatt@apple.com> 2 15 -
trunk/LayoutTests/fast/dom/Range/range-exceptions-expected.txt
r14516 r30123 1 This test checks a few DOM range exceptions.1 This test checks some DOM Range exceptions. 2 2 3 3 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". … … 7 7 PASS foo.outerHTML is '<foo></foo>' 8 8 PASS range.surroundContents(foo) threw exception Error: BAD_BOUNDARYPOINTS_ERR: DOM Range Exception 1. 9 PASS r.surroundContents(document.createElement('a')) threw exception Error: BAD_BOUNDARYPOINTS_ERR: DOM Range Exception 1. 10 PASS r.surroundContents(document.createElement('a')) threw exception Error: HIERARCHY_REQUEST_ERR: DOM Exception 3. 9 11 PASS successfullyParsed is true 10 12 -
trunk/LayoutTests/fast/dom/Range/resources/range-exceptions.js
r14516 r30123 1 1 description( 2 "This test checks a few DOM range exceptions."2 "This test checks some DOM Range exceptions." 3 3 ); 4 4 … … 14 14 shouldThrow("range.surroundContents(foo)"); 15 15 16 // Ensure that we throw BAD_BOUNDARYPOINTS_ERR when trying to split a comment 17 // (non-text but character-offset node). (Test adapted from Acid3.) 18 var c1 = document.createComment("aaaaa"); 19 node.appendChild(c1); 20 var c2 = document.createComment("bbbbb"); 21 node.appendChild(c2); 22 var r = document.createRange(); 23 r.setStart(c1, 2); 24 r.setEnd(c2, 3); 25 shouldThrow("r.surroundContents(document.createElement('a'))", '"Error: BAD_BOUNDARYPOINTS_ERR: DOM Range Exception 1"'); 26 27 // But not when we don't try to split the comment. 28 r.setStart(c1, 0); 29 r.setEnd(c1, 5); 30 shouldThrow("r.surroundContents(document.createElement('a'))", '"Error: HIERARCHY_REQUEST_ERR: DOM Exception 3"'); 31 16 32 var successfullyParsed = true; -
trunk/WebCore/ChangeLog
r30122 r30123 1 2008-02-10 Andrew Wellington <proton@wiretapped.net> 2 3 Reviewed and tweaked by Darin. 4 5 DOMRange.surroundContents throws wrong exception (Acid3 bug) 6 http://bugs.webkit.org/show_bug.cgi?id=16749 7 8 Throw BAD_BOUNDARYPOINTS_ERR if attempting to split a non-text node that 9 has offsets in characters. 10 11 * dom/Range.cpp: 12 (WebCore::Range::surroundContents): 13 1 14 2008-02-10 Darin Adler <darin@apple.com> 2 15 -
trunk/WebCore/dom/Range.cpp
r30122 r30123 365 365 366 366 // compare to end, and point comes after 367 elseif (compareBoundaryPoints(refNode, offset, m_endContainer.get(), m_endOffset) == 1)367 if (compareBoundaryPoints(refNode, offset, m_endContainer.get(), m_endOffset) == 1) 368 368 return 1; 369 369 370 370 // point is in the middle of this range, or on the boundary points 371 else 372 return 0; 371 return 0; 373 372 } 374 373 … … 1169 1168 void Range::checkNodeWOffset(Node* n, int offset, ExceptionCode& ec) const 1170 1169 { 1171 if (offset < 0)1172 ec = INDEX_SIZE_ERR;1173 // no return here1174 1175 1170 switch (n->nodeType()) { 1171 case Node::DOCUMENT_TYPE_NODE: 1176 1172 case Node::ENTITY_NODE: 1177 1173 case Node::NOTATION_NODE: 1178 case Node::DOCUMENT_TYPE_NODE:1179 1174 ec = RangeException::INVALID_NODE_TYPE_ERR; 1180 break; 1175 return; 1176 case Node::CDATA_SECTION_NODE: 1177 case Node::COMMENT_NODE: 1181 1178 case Node::TEXT_NODE: 1182 case Node::COMMENT_NODE: 1183 case Node::CDATA_SECTION_NODE: 1184 if ((unsigned)offset > static_cast<CharacterData*>(n)->length()) 1179 if (static_cast<unsigned>(offset) > static_cast<CharacterData*>(n)->length()) 1185 1180 ec = INDEX_SIZE_ERR; 1186 break;1181 return; 1187 1182 case Node::PROCESSING_INSTRUCTION_NODE: 1188 if ( (unsigned)offset> static_cast<ProcessingInstruction*>(n)->data().length())1183 if (static_cast<unsigned>(offset) > static_cast<ProcessingInstruction*>(n)->data().length()) 1189 1184 ec = INDEX_SIZE_ERR; 1190 break; 1191 default: 1192 if ((unsigned)offset > n->childNodeCount()) 1185 return; 1186 case Node::ATTRIBUTE_NODE: 1187 case Node::DOCUMENT_FRAGMENT_NODE: 1188 case Node::DOCUMENT_NODE: 1189 case Node::ELEMENT_NODE: 1190 case Node::ENTITY_REFERENCE_NODE: 1191 case Node::XPATH_NAMESPACE_NODE: 1192 if (static_cast<unsigned>(offset) > n->childNodeCount()) 1193 1193 ec = INDEX_SIZE_ERR; 1194 break; 1195 } 1196 } 1197 1198 void Range::checkNodeBA( Node *n, ExceptionCode& ec) const 1194 return; 1195 } 1196 ASSERT_NOT_REACHED(); 1197 } 1198 1199 void Range::checkNodeBA(Node* n, ExceptionCode& ec) const 1199 1200 { 1200 1201 // INVALID_NODE_TYPE_ERR: Raised if the root container of refNode is not an … … 1204 1205 while (root->parentNode()) 1205 1206 root = root->parentNode(); 1207 1206 1208 if (!(root->nodeType() == Node::ATTRIBUTE_NODE || 1207 1209 root->nodeType() == Node::DOCUMENT_NODE || … … 1378 1380 m_startOffset = 0; 1379 1381 m_endContainer = refNode; 1380 m_endOffset = refNode->offsetInCharacters() ? refNode->maxCharacterOffset() : refNode->childNodeCount();1382 m_endOffset = maxEndOffset(); 1381 1383 } 1382 1384 … … 1397 1399 // INVALID_NODE_TYPE_ERR: Raised if node is an Attr, Entity, DocumentType, Notation, 1398 1400 // Document, or DocumentFragment node. 1399 if( newParent->nodeType() == Node::ATTRIBUTE_NODE || 1400 newParent->nodeType() == Node::ENTITY_NODE || 1401 newParent->nodeType() == Node::NOTATION_NODE || 1402 newParent->nodeType() == Node::DOCUMENT_TYPE_NODE || 1403 newParent->nodeType() == Node::DOCUMENT_NODE || 1404 newParent->nodeType() == Node::DOCUMENT_FRAGMENT_NODE) { 1405 ec = RangeException::INVALID_NODE_TYPE_ERR; 1406 return; 1401 switch (newParent->nodeType()) { 1402 case Node::ATTRIBUTE_NODE: 1403 case Node::DOCUMENT_FRAGMENT_NODE: 1404 case Node::DOCUMENT_NODE: 1405 case Node::DOCUMENT_TYPE_NODE: 1406 case Node::ENTITY_NODE: 1407 case Node::NOTATION_NODE: 1408 ec = RangeException::INVALID_NODE_TYPE_ERR; 1409 return; 1410 case Node::CDATA_SECTION_NODE: 1411 case Node::COMMENT_NODE: 1412 case Node::ELEMENT_NODE: 1413 case Node::ENTITY_REFERENCE_NODE: 1414 case Node::PROCESSING_INSTRUCTION_NODE: 1415 case Node::TEXT_NODE: 1416 case Node::XPATH_NAMESPACE_NODE: 1417 break; 1407 1418 } 1408 1419 … … 1420 1431 return; 1421 1432 } 1433 1434 // BAD_BOUNDARYPOINTS_ERR: Raised if the Range partially selects a non-Text node. 1435 // FIXME: The specification says non-Text. What does that mean about CDataSection, which 1436 // is a kind of Text node? Use isTextNode() instead of nodeType() to include CDataSection? 1437 if (m_startContainer->nodeType() != Node::TEXT_NODE) { 1438 if (m_startOffset > 0 && m_startOffset < maxStartOffset()) { 1439 ec = RangeException::BAD_BOUNDARYPOINTS_ERR; 1440 return; 1441 } 1442 } 1443 if (m_endContainer->nodeType() != Node::TEXT_NODE) { 1444 if (m_endOffset > 0 && m_endOffset < maxEndOffset()) { 1445 ec = RangeException::BAD_BOUNDARYPOINTS_ERR; 1446 return; 1447 } 1448 } 1422 1449 1423 1450 // Raise a HIERARCHY_REQUEST_ERR if m_startContainer doesn't accept children like newParent. … … 1437 1464 } 1438 1465 1439 // ### check if node would end up with a child node of a type not allowed by the type of node 1440 1441 // BAD_BOUNDARYPOINTS_ERR: Raised if the Range partially selects a non-text node. 1442 if (!m_startContainer->offsetInCharacters()) { 1443 if (m_startOffset > 0 && m_startOffset < m_startContainer->childNodeCount()) { 1444 ec = RangeException::BAD_BOUNDARYPOINTS_ERR; 1445 return; 1446 } 1447 } 1448 if (!m_endContainer->offsetInCharacters()) { 1449 if (m_endOffset > 0 && m_endOffset < m_endContainer->childNodeCount()) { 1450 ec = RangeException::BAD_BOUNDARYPOINTS_ERR; 1451 return; 1452 } 1453 } 1466 // FIXME: Do we need a check if the node would end up with a child node of a type not 1467 // allowed by the type of node? 1454 1468 1455 1469 ec = 0; … … 1684 1698 } 1685 1699 1686 } 1700 unsigned Range::maxStartOffset() const 1701 { 1702 if (!m_startContainer) 1703 return 0; 1704 if (!m_startContainer->offsetInCharacters()) 1705 return m_startContainer->childNodeCount(); 1706 return m_startContainer->maxCharacterOffset(); 1707 } 1708 1709 unsigned Range::maxEndOffset() const 1710 { 1711 if (!m_endContainer) 1712 return 0; 1713 if (!m_endContainer->offsetInCharacters()) 1714 return m_endContainer->childNodeCount(); 1715 return m_endContainer->maxCharacterOffset(); 1716 } 1717 1718 } -
trunk/WebCore/dom/Range.h
r27776 r30123 132 132 void checkDeleteExtract(ExceptionCode&); 133 133 bool containedByReadOnly() const; 134 unsigned maxStartOffset() const; 135 unsigned maxEndOffset() const; 134 136 }; 135 137
Note: See TracChangeset
for help on using the changeset viewer.