Fix up text/plain message view to escape < and > and & when converting plain text to html for display

This commit is contained in:
Jesse Vincent 2009-05-02 22:06:42 +00:00
parent 0ffe1621a2
commit d185adfc27
1 changed files with 9 additions and 6 deletions

View File

@ -1068,6 +1068,15 @@ public class MessageView extends Activity
} else {
Matcher m = Regex.WEB_URL_PATTERN.matcher(text);
StringBuffer sb = new StringBuffer();
/*
* Convert plain text to HTML by replacing
* \r?\n with <br> and adding a html/body wrapper as well as escaping & < >
*/
text = text.replaceAll("&", "&amp;");
text = text.replaceAll("<", "&lt;");
text = text.replaceAll(">", "&gt;");
text = text.replaceAll("\r?\n", "<br>");
while (m.find()) {
int start = m.start();
if (start == 0 || (start != 0 && text.charAt(start - 1) != '@')) {
@ -1079,12 +1088,6 @@ public class MessageView extends Activity
}
m.appendTail(sb);
/*
* Convert plain text to HTML by replacing
* \r?\n with <br> and adding a html/body wrapper.
*/
text = sb.toString().replaceAll("\r?\n", "<br>");
text = "<html><body>" + text + "</body></html>";