diff --git a/editor/base/nsHTMLEditor.cpp b/editor/base/nsHTMLEditor.cpp
index 6884c70b1b3e..9300ceb1226c 100644
--- a/editor/base/nsHTMLEditor.cpp
+++ b/editor/base/nsHTMLEditor.cpp
@@ -5661,7 +5661,9 @@ nsHTMLEditor::CollapseAdjacentTextNodes(nsIDOMRange *aInRange)
iter->Init(aInRange);
nsCOMPtr content;
- result = iter->CurrentNode(getter_AddRefs(content));
+ result = iter->CurrentNode(getter_AddRefs(content));
+ if (!content) return NS_OK;
+
while (NS_ENUMERATOR_FALSE == iter->IsDone())
{
nsCOMPtr text = do_QueryInterface(content);
diff --git a/editor/libeditor/html/nsHTMLEditor.cpp b/editor/libeditor/html/nsHTMLEditor.cpp
index 6884c70b1b3e..9300ceb1226c 100644
--- a/editor/libeditor/html/nsHTMLEditor.cpp
+++ b/editor/libeditor/html/nsHTMLEditor.cpp
@@ -5661,7 +5661,9 @@ nsHTMLEditor::CollapseAdjacentTextNodes(nsIDOMRange *aInRange)
iter->Init(aInRange);
nsCOMPtr content;
- result = iter->CurrentNode(getter_AddRefs(content));
+ result = iter->CurrentNode(getter_AddRefs(content));
+ if (!content) return NS_OK;
+
while (NS_ENUMERATOR_FALSE == iter->IsDone())
{
nsCOMPtr text = do_QueryInterface(content);