Bug 1345015 - Part 2. Don't promote range when selection node isn't content. r=masayuki draft
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Mon, 10 Jul 2017 16:17:06 +0900
changeset 606068 04c4e4a2e04a0d0a058eb86fdfde0005edb681a9
parent 606067 bb13c4531fb76684d4baf13e24dc777d79c2ad61
child 606069 322a77cbc49e29bbd6b705650485634dd4801b8b
push id67595
push userm_kato@ga2.so-net.ne.jp
push dateMon, 10 Jul 2017 09:03:51 +0000
reviewersmasayuki
bugs1345015
milestone56.0a1
Bug 1345015 - Part 2. Don't promote range when selection node isn't content. r=masayuki When using EditAction::insertBreak action, if selection node isn't content, this crash occurs. So we should reject to promote range when it isn't content node. MozReview-Commit-ID: AJ4oEOmRTgm
editor/libeditor/HTMLEditRules.cpp
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -5693,16 +5693,28 @@ HTMLEditRules::PromoteRange(nsRange& aRa
         startNode = block;
         endNode = block;
         startOffset = 0;
         endOffset = block->Length();
       }
     }
   }
 
+  if (aOperationType == EditAction::insertText ||
+      aOperationType == EditAction::insertIMEText ||
+      aOperationType == EditAction::insertBreak ||
+      aOperationType == EditAction::deleteText) {
+     if (!startNode->IsContent() ||
+         !endNode->IsContent()) {
+       // GetPromotedPoint cannot promote node when action type is text
+       // operation and selected node isn't content node.
+       return;
+     }
+  }
+
   // Make a new adjusted range to represent the appropriate block content.
   // This is tricky.  The basic idea is to push out the range endpoints to
   // truly enclose the blocks that we will affect.
 
   EditorDOMPoint opStart =
     GetPromotedPoint(kStart, *startNode, startOffset, aOperationType);
   EditorDOMPoint opEnd =
     GetPromotedPoint(kEnd, *endNode, endOffset, aOperationType);