Changeset 30123 in webkit


Ignore:
Timestamp:
Feb 10, 2008 12:13:51 PM (16 years ago)
Author:
Darin Adler
Message:

WebCore:

Reviewed and tweaked by Darin.


DOMRange.surroundContents throws wrong exception (Acid3 bug)
http://bugs.webkit.org/show_bug.cgi?id=16749


Throw BAD_BOUNDARYPOINTS_ERR if attempting to split a non-text node that
has offsets in characters.

  • dom/Range.cpp: (WebCore::Range::surroundContents):

LayoutTests:

Reviewed and tweaked a bit by Darin.


DOMRange.surroundContents throws wrong exception (Acid3 bug)
http://bugs.webkit.org/show_bug.cgi?id=16749


Throw BAD_BOUNDARYPOINTS_ERR if attempting to split a non-text node that
has offsets in characters

  • fast/dom/Range/range-exceptions-expected.txt: Added.
  • fast/dom/Range/resources/range-exceptions.js: Added.
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r30116 r30123  
     12008-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
    1142008-02-09  David Hyatt  <hyatt@apple.com>
    215
  • trunk/LayoutTests/fast/dom/Range/range-exceptions-expected.txt

    r14516 r30123  
    1 This test checks a few DOM range exceptions.
     1This test checks some DOM Range exceptions.
    22
    33On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
     
    77PASS foo.outerHTML is '<foo></foo>'
    88PASS range.surroundContents(foo) threw exception Error: BAD_BOUNDARYPOINTS_ERR: DOM Range Exception 1.
     9PASS r.surroundContents(document.createElement('a')) threw exception Error: BAD_BOUNDARYPOINTS_ERR: DOM Range Exception 1.
     10PASS r.surroundContents(document.createElement('a')) threw exception Error: HIERARCHY_REQUEST_ERR: DOM Exception 3.
    911PASS successfullyParsed is true
    1012
  • trunk/LayoutTests/fast/dom/Range/resources/range-exceptions.js

    r14516 r30123  
    11description(
    2 "This test checks a few DOM range exceptions."
     2"This test checks some DOM Range exceptions."
    33);
    44
     
    1414shouldThrow("range.surroundContents(foo)");
    1515
     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.)
     18var c1 = document.createComment("aaaaa");
     19node.appendChild(c1);
     20var c2 = document.createComment("bbbbb");
     21node.appendChild(c2);
     22var r = document.createRange();
     23r.setStart(c1, 2);
     24r.setEnd(c2, 3);
     25shouldThrow("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.
     28r.setStart(c1, 0);
     29r.setEnd(c1, 5);
     30shouldThrow("r.surroundContents(document.createElement('a'))", '"Error: HIERARCHY_REQUEST_ERR: DOM Exception 3"');
     31
    1632var successfullyParsed = true;
  • trunk/WebCore/ChangeLog

    r30122 r30123  
     12008-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
    1142008-02-10  Darin Adler  <darin@apple.com>
    215
  • trunk/WebCore/dom/Range.cpp

    r30122 r30123  
    365365
    366366    // compare to end, and point comes after
    367     else if (compareBoundaryPoints(refNode, offset, m_endContainer.get(), m_endOffset) == 1)
     367    if (compareBoundaryPoints(refNode, offset, m_endContainer.get(), m_endOffset) == 1)
    368368        return 1;
    369    
     369
    370370    // point is in the middle of this range, or on the boundary points
    371     else
    372         return 0;
     371    return 0;
    373372}
    374373
     
    11691168void Range::checkNodeWOffset(Node* n, int offset, ExceptionCode& ec) const
    11701169{
    1171     if (offset < 0)
    1172         ec = INDEX_SIZE_ERR;
    1173         // no return here
    1174 
    11751170    switch (n->nodeType()) {
     1171        case Node::DOCUMENT_TYPE_NODE:
    11761172        case Node::ENTITY_NODE:
    11771173        case Node::NOTATION_NODE:
    1178         case Node::DOCUMENT_TYPE_NODE:
    11791174            ec = RangeException::INVALID_NODE_TYPE_ERR;
    1180             break;
     1175            return;
     1176        case Node::CDATA_SECTION_NODE:
     1177        case Node::COMMENT_NODE:
    11811178        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())
    11851180                ec = INDEX_SIZE_ERR;
    1186             break;
     1181            return;
    11871182        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())
    11891184                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())
    11931193                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
     1199void Range::checkNodeBA(Node* n, ExceptionCode& ec) const
    11991200{
    12001201    // INVALID_NODE_TYPE_ERR: Raised if the root container of refNode is not an
     
    12041205    while (root->parentNode())
    12051206        root = root->parentNode();
     1207
    12061208    if (!(root->nodeType() == Node::ATTRIBUTE_NODE ||
    12071209          root->nodeType() == Node::DOCUMENT_NODE ||
     
    13781380    m_startOffset = 0;
    13791381    m_endContainer = refNode;
    1380     m_endOffset = refNode->offsetInCharacters() ? refNode->maxCharacterOffset() : refNode->childNodeCount();
     1382    m_endOffset = maxEndOffset();
    13811383}
    13821384
     
    13971399    // INVALID_NODE_TYPE_ERR: Raised if node is an Attr, Entity, DocumentType, Notation,
    13981400    // 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;
    14071418    }
    14081419
     
    14201431        return;
    14211432    }
     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    }   
    14221449
    14231450    // Raise a HIERARCHY_REQUEST_ERR if m_startContainer doesn't accept children like newParent.
     
    14371464    }
    14381465
    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?
    14541468
    14551469    ec = 0;
     
    16841698}
    16851699
    1686 }
     1700unsigned 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
     1709unsigned 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  
    132132    void checkDeleteExtract(ExceptionCode&);
    133133    bool containedByReadOnly() const;
     134    unsigned maxStartOffset() const;
     135    unsigned maxEndOffset() const;
    134136};
    135137
Note: See TracChangeset for help on using the changeset viewer.