diff --git a/editor/libeditor/AutoRangeArray.cpp b/editor/libeditor/AutoRangeArray.cpp index 57b9b26a3546..782ceaf00bb5 100644 --- a/editor/libeditor/AutoRangeArray.cpp +++ b/editor/libeditor/AutoRangeArray.cpp @@ -665,6 +665,7 @@ GetPointAtFirstContentOfLineOrParentHTMLBlockIfFirstContentOfBlock( // If we're formatting a block, we should reformat first ancestor format // block. if (aEditSubAction == EditSubAction::eFormatBlockForHTMLCommand && + point.IsContainerElement() && HTMLEditUtils::IsFormatElementForFormatBlockCommand( *point.ContainerAs())) { point.Set(point.GetContainer()); @@ -836,6 +837,7 @@ static EditorDOMPoint GetPointAfterFollowingLineBreakOrAtFollowingHTMLBlock( // If we're formatting a block, we should reformat first ancestor format // block. if (aEditSubAction == EditSubAction::eFormatBlockForHTMLCommand && + point.IsContainerElement() && HTMLEditUtils::IsFormatElementForFormatBlockCommand( *point.ContainerAs())) { point.SetAfter(point.GetContainer()); diff --git a/editor/libeditor/EditorDOMPoint.h b/editor/libeditor/EditorDOMPoint.h index 907b02f059e1..2f5d35ed6eff 100644 --- a/editor/libeditor/EditorDOMPoint.h +++ b/editor/libeditor/EditorDOMPoint.h @@ -278,6 +278,11 @@ class EditorDOMPointBase final { return mParent && mParent->IsInNativeAnonymousSubtree(); } + /** + * Returns true if the container node is an element node. + */ + bool IsContainerElement() const { return mParent && mParent->IsElement(); } + /** * IsContainerHTMLElement() returns true if the container node is an HTML * element node and its node name is aTag. diff --git a/testing/web-platform/tests/editing/crashtests/formatblock-when-root-is-editing-host.html b/testing/web-platform/tests/editing/crashtests/formatblock-when-root-is-editing-host.html new file mode 100644 index 000000000000..b888b897bbc8 --- /dev/null +++ b/testing/web-platform/tests/editing/crashtests/formatblock-when-root-is-editing-host.html @@ -0,0 +1,16 @@ + + + + + + + +text + \ No newline at end of file