Bug 254298 - nsPlainTextSerializer.cpp should not use AssignWithConversion. r=smaug
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Fri, 04 Nov 2011 17:44:13 +0900
changeset 79754 89649127982e99657d92ac449421388e79149e9f
parent 79753 ab09b7c7a7a874a4d17bc066b13b037782af61c4
child 79755 2ee987590740caf5f974613aca5b397d869a5b57
push id21423
push usermbrubeck@mozilla.com
push dateFri, 04 Nov 2011 18:28:39 +0000
treeherdermozilla-central@5ebd59b5a94a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs254298
milestone10.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 254298 - nsPlainTextSerializer.cpp should not use AssignWithConversion. r=smaug
content/base/src/nsPlainTextSerializer.cpp
--- a/content/base/src/nsPlainTextSerializer.cpp
+++ b/content/base/src/nsPlainTextSerializer.cpp
@@ -302,38 +302,39 @@ nsPlainTextSerializer::AppendText(nsICon
     
   NS_ASSERTION(aStartOffset >= 0, "Negative start offset for text fragment!");
   if ( aStartOffset < 0 )
     return NS_ERROR_INVALID_ARG;
 
   NS_ENSURE_ARG(aText);
 
   nsresult rv = NS_OK;
-  PRInt32 length = 0;
-  nsAutoString textstr;
 
   nsIContent* content = aText;
   const nsTextFragment* frag;
   if (!content || !(frag = content->GetText())) {
     return NS_ERROR_FAILURE;
   }
   
   PRInt32 endoffset = (aEndOffset == -1) ? frag->GetLength() : aEndOffset;
   NS_ASSERTION(aStartOffset <= endoffset, "A start offset is beyond the end of the text fragment!");
 
-  length = endoffset - aStartOffset;
+  PRInt32 length = endoffset - aStartOffset;
   if (length <= 0) {
     return NS_OK;
   }
 
+  nsAutoString textstr;
   if (frag->Is2b()) {
     textstr.Assign(frag->Get2b() + aStartOffset, length);
   }
   else {
-    textstr.AssignWithConversion(frag->Get1b()+aStartOffset, length);
+    // AssignASCII is for 7-bit character only, so don't use it
+    const char *data = frag->Get1b();
+    CopyASCIItoUTF16(Substring(data + aStartOffset, data + endoffset), textstr);
   }
 
   mOutputString = &aStr;
 
   // We have to split the string across newlines
   // to match parser behavior
   PRInt32 start = 0;
   PRInt32 offset = textstr.FindCharInSet("\n\r");