⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 284792 in webkit


Ignore:
Timestamp:
Oct 25, 2021, 10:48:24 AM (5 years ago)
Author:
commit-queue@webkit.org
Message:

Source/WebCore:
ASSERT(node) triggered after surroundNodeRangeWithElement for node without editable style
https://bugs.webkit.org/show_bug.cgi?id=232133

Patch by Gabriel Nava Marino <gnavamarino@apple.com> on 2021-10-25
Reviewed by Wenson Hsieh.

If the last styled node was not parent node of a current text node, but we
wish to style the text node, we will add a style span to surround the text node.
However, this requires the parent to have an editable style, or
we will not properly insert the span in the right location, which
later leads to a traversal into an invalid node. This change
makes it so we return early if the parent node does not have an
editable style, but modifying the existing
CompositeEditCommand::insertNodeBefore to return a boolean in the
early return case.

Test: fast/editing/apply-relative-font-style-change-crash-003.html

  • editing/ApplyStyleCommand.cpp:

(WebCore::ApplyStyleCommand::surroundNodeRangeWithElement):

  • editing/CompositeEditCommand.cpp:

(WebCore::CompositeEditCommand::insertNodeBefore):

  • editing/CompositeEditCommand.h:

LayoutTests:
ASSERT(node) triggered after surroundNodeRangeWithElement for node without editable style
https://bugs.webkit.org/show_bug.cgi?id=232133

Patch by Gabriel Nava Marino <gnavamarino@apple.com> on 2021-10-25
Reviewed by Wenson Hsieh.

  • fast/editing/apply-relative-font-style-change-crash-003-expected.txt: Added.
  • fast/editing/apply-relative-font-style-change-crash-003.html: Added.
Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r284790 r284792  
     12021-10-25  Gabriel Nava Marino  <gnavamarino@apple.com>
     2
     3        ASSERT(node) triggered after surroundNodeRangeWithElement for node without editable style
     4        https://bugs.webkit.org/show_bug.cgi?id=232133
     5
     6        Reviewed by Wenson Hsieh.
     7
     8        * fast/editing/apply-relative-font-style-change-crash-003-expected.txt: Added.
     9        * fast/editing/apply-relative-font-style-change-crash-003.html: Added.
     10
    1112021-10-25  Ayumi Kojima  <ayumi_kojima@apple.com>
    212
  • trunk/Source/WebCore/ChangeLog

    r284789 r284792  
     12021-10-25  Gabriel Nava Marino  <gnavamarino@apple.com>
     2
     3        ASSERT(node) triggered after surroundNodeRangeWithElement for node without editable style
     4        https://bugs.webkit.org/show_bug.cgi?id=232133
     5
     6        Reviewed by Wenson Hsieh.
     7       
     8        If the last styled node was not parent node of a current text node, but we
     9        wish to style the text node, we will add a style span to surround the text node.
     10        However, this requires the parent to have an editable style, or
     11        we will not properly insert the span in the right location, which
     12        later leads to a traversal into an invalid node. This change
     13        makes it so we return early if the parent node does not have an
     14        editable style, but modifying the existing
     15        CompositeEditCommand::insertNodeBefore to return a boolean in the
     16        early return case.
     17
     18        Test: fast/editing/apply-relative-font-style-change-crash-003.html
     19
     20        * editing/ApplyStyleCommand.cpp:
     21        (WebCore::ApplyStyleCommand::surroundNodeRangeWithElement):
     22        * editing/CompositeEditCommand.cpp:
     23        (WebCore::CompositeEditCommand::insertNodeBefore):
     24        * editing/CompositeEditCommand.h:
     25
    1262021-10-25  Darin Adler  <darin@apple.com>
    227
  • trunk/Source/WebCore/editing/ApplyStyleCommand.cpp

    r284739 r284792  
    13201320    Ref<Element> element = WTFMove(elementToInsert);
    13211321
    1322     insertNodeBefore(element.copyRef(), startNode);
    1323     if (!element->isContentRichlyEditable()) {
     1322    if (!insertNodeBefore(element.copyRef(), startNode) || !element->isContentRichlyEditable()) {
    13241323        removeNode(element);
    13251324        return false;
  • trunk/Source/WebCore/editing/CompositeEditCommand.cpp

    r284269 r284792  
    553553}
    554554
    555 void CompositeEditCommand::insertNodeBefore(Ref<Node>&& insertChild, Node& refChild, ShouldAssumeContentIsAlwaysEditable shouldAssumeContentIsAlwaysEditable)
     555bool CompositeEditCommand::insertNodeBefore(Ref<Node>&& insertChild, Node& refChild, ShouldAssumeContentIsAlwaysEditable shouldAssumeContentIsAlwaysEditable)
    556556{
    557557    RefPtr parent { refChild.parentNode() };
    558558    if (!parent || (!parent->hasEditableStyle() && parent->renderer()))
    559         return;
     559        return false;
    560560    applyCommandToComposite(InsertNodeBeforeCommand::create(WTFMove(insertChild), refChild, shouldAssumeContentIsAlwaysEditable, editingAction()));
     561    return true;
    561562}
    562563
  • trunk/Source/WebCore/editing/CompositeEditCommand.h

    r281795 r284792  
    155155    void insertNodeAt(Ref<Node>&&, const Position&);
    156156    void insertNodeAtTabSpanPosition(Ref<Node>&&, const Position&);
    157     void insertNodeBefore(Ref<Node>&&, Node& refChild, ShouldAssumeContentIsAlwaysEditable = DoNotAssumeContentIsAlwaysEditable);
     157    bool insertNodeBefore(Ref<Node>&&, Node& refChild, ShouldAssumeContentIsAlwaysEditable = DoNotAssumeContentIsAlwaysEditable);
    158158    void insertParagraphSeparatorAtPosition(const Position&, bool useDefaultParagraphElement = false, bool pasteBlockqutoeIntoUnquotedArea = false);
    159159    void insertParagraphSeparator(bool useDefaultParagraphElement = false, bool pasteBlockqutoeIntoUnquotedArea = false);
Note: See TracChangeset for help on using the changeset viewer.