Bug 556734, r=bz, a=blocking-1.9.2.11+
--- 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