From 2a20dd1b9438d67592bd68c62685963b4eb2a813 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ryszard=20Wi=C5=9Bniewski?= Date: Sun, 13 Jun 2010 16:14:29 +0200 Subject: [PATCH] StringBlock.getHTML(): escape XML chars before styling. --- src/brut/androlib/res/decoder/StringBlock.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/brut/androlib/res/decoder/StringBlock.java b/src/brut/androlib/res/decoder/StringBlock.java index 5a2ff0bf..f07c38a1 100644 --- a/src/brut/androlib/res/decoder/StringBlock.java +++ b/src/brut/androlib/res/decoder/StringBlock.java @@ -125,7 +125,7 @@ public class StringBlock { } int[] style = getStyle(index); if (style == null) { - return raw; + return escapeForXml(raw); } StringBuilder html = new StringBuilder(raw.length() + 32); int offset = 0; @@ -146,7 +146,7 @@ public class StringBlock { continue; } if (offset <= end) { - html.append(raw, offset, end + 1); + html.append(escapeForXml(raw.substring(offset, end + 1))); offset = end + 1; } style[j + 2] = -1; @@ -156,7 +156,7 @@ public class StringBlock { html.append('>'); } if (offset < start) { - html.append(raw, offset, start); + html.append(escapeForXml(raw.substring(offset, start))); offset = start; } if (i == -1) { @@ -170,6 +170,10 @@ public class StringBlock { return html.toString(); } + private String escapeForXml(String txt) { + return txt.replace("&", "&").replace("<", "<"); + } + /** * Finds index of the string. * Returns -1 if the string was not found.