Index: Source/core/editing/ReplaceSelectionCommand.cpp |
diff --git a/Source/core/editing/ReplaceSelectionCommand.cpp b/Source/core/editing/ReplaceSelectionCommand.cpp |
index f86777b2ee129597dcadf87fefacdf53da26695b..39f6c41db951380ae6891917fa5676279ac97efd 100644 |
--- a/Source/core/editing/ReplaceSelectionCommand.cpp |
+++ b/Source/core/editing/ReplaceSelectionCommand.cpp |
@@ -754,7 +754,8 @@ void ReplaceSelectionCommand::handleStyleSpans(InsertedNodes& insertedNodes) |
// The style span that contains the source document's default style should be at |
// the top of the fragment, but Mail sometimes adds a wrapper (for Paste As Quotation), |
// so search for the top level style span instead of assuming it's at the top. |
- for (Node* node = insertedNodes.firstNodeInserted(); node; node = NodeTraversal::next(*node)) { |
+ Node* pastEndNode = insertedNodes.pastLastLeaf(); |
+ for (Node* node = insertedNodes.firstNodeInserted(); node && node != pastEndNode; node = NodeTraversal::next(*node)) { |
if (isLegacyAppleStyleSpan(node)) { |
wrappingStyleSpan = toHTMLElement(node); |
break; |