diff --git a/content/base/src/nsHTMLContentSerializer.cpp b/content/base/src/nsHTMLContentSerializer.cpp
index 148c9f6533a..a4dda335bc1 100644
--- a/content/base/src/nsHTMLContentSerializer.cpp
+++ b/content/base/src/nsHTMLContentSerializer.cpp
@@ -787,6 +787,9 @@ nsHTMLContentSerializer::AppendToStringWrapped(const nsASingleFragmentString& aS
}
}
+static PRUint16 kValNBSP = 160;
+static const char* kEntityNBSP = "nbsp";
+
static PRUint16 kGTVal = 62;
static const char* kEntities[] = {
"", "", "", "", "", "", "", "", "", "",
@@ -856,7 +859,11 @@ nsHTMLContentSerializer::AppendToString(const nsAString& aStr,
// needs to be replaced
for (; c < fragmentEnd; c++, advanceLength++) {
PRUnichar val = *c;
- if ((val <= kGTVal) && (entityTable[val][0] != 0)) {
+ if (val == kValNBSP) {
+ entityText = kEntityNBSP;
+ break;
+ }
+ else if ((val <= kGTVal) && (entityTable[val][0] != 0)) {
entityText = entityTable[val];
break;
} else if (mIsLatin1 && val > 127 && val < 256) {
diff --git a/content/html/content/src/nsGenericHTMLElement.cpp b/content/html/content/src/nsGenericHTMLElement.cpp
index 2581b7e2afb..1d3cb915913 100644
--- a/content/html/content/src/nsGenericHTMLElement.cpp
+++ b/content/html/content/src/nsGenericHTMLElement.cpp
@@ -880,7 +880,8 @@ nsGenericHTMLElement::GetInnerHTML(nsAString& aInnerHTML)
NS_ENSURE_TRUE(docEncoder, NS_ERROR_FAILURE);
- docEncoder->Init(doc, NS_LITERAL_STRING("text/html"), 0);
+ docEncoder->Init(doc, NS_LITERAL_STRING("text/html"),
+ nsIDocumentEncoder::OutputEncodeEntities);
nsCOMPtr range(new nsRange);
NS_ENSURE_TRUE(range, NS_ERROR_OUT_OF_MEMORY);