Bug 556734, r=bz, a=blocking-1.9.2.11+
authorHonza Bambas <honzab.moz@firemni.cz>
Thu, 23 Sep 2010 15:49:33 +0200
changeset 34598 55bad5ea82c96bc9a2583114ddc04fff17031ce8
parent 34597 f070c6116d9d38685cde35a0ff95b4706231bca7
child 34599 d4f62917d5637b5ac2b926eac7653dc334ce2722
push id1575
push userhonzab.moz@firemni.cz
push dateThu, 23 Sep 2010 13:53:56 +0000
reviewersbz, blocking-1.9.2.11
bugs556734
milestone1.9.2.11pre
Bug 556734, r=bz, a=blocking-1.9.2.11+
netwerk/streamconv/converters/nsTXTToHTMLConv.cpp
--- a/netwerk/streamconv/converters/nsTXTToHTMLConv.cpp
+++ b/netwerk/streamconv/converters/nsTXTToHTMLConv.cpp
@@ -32,16 +32,17 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsTXTToHTMLConv.h"
 #include "nsNetUtil.h"
+#include "nsEscape.h"
 #include "nsStringStream.h"
 #include "nsAutoPtr.h"
 
 #define TOKEN_DELIMITERS NS_LITERAL_STRING("\t\r\n ").get()
 
 // nsISupports methods
 NS_IMPL_ISUPPORTS4(nsTXTToHTMLConv,
                    nsIStreamConverter,
@@ -304,21 +305,34 @@ nsTXTToHTMLConv::CatHTML(PRInt32 front, 
         // replace the entire token (from delimiter to delimiter)
         mBuffer.Cut(front, back - front);
         mBuffer.Insert(mToken->modText, front);
         cursor = front+modLen;
     } else {
         nsString linkText;
         // href is implied
         mBuffer.Mid(linkText, front, back-front);
+
         mBuffer.Insert(NS_LITERAL_STRING("<a href=\""), front);
         cursor += front+9;
-        if (modLen)
+        if (modLen) {
             mBuffer.Insert(mToken->modText, cursor);
-        cursor += modLen-front+back;
+            cursor += modLen;
+        }
+
+        NS_ConvertUTF16toUTF8 linkTextUTF8(linkText);
+        nsCString escaped;
+        if (NS_EscapeURL(linkTextUTF8.Data(), linkTextUTF8.Length(), esc_Minimal, escaped)) {
+            mBuffer.Cut(cursor, back - front);
+            CopyUTF8toUTF16(escaped, linkText);
+            mBuffer.Insert(linkText, cursor);
+            back = front + linkText.Length();
+        }
+
+        cursor += back-front;
         mBuffer.Insert(NS_LITERAL_STRING("\">"), cursor);
         cursor += 2;
         mBuffer.Insert(linkText, cursor);
         cursor += linkText.Length();
         mBuffer.Insert(NS_LITERAL_STRING("</a>"), cursor);
         cursor += 4;
     }
     mToken = nsnull; // indicates completeness