Commit 7c34be26 authored by Skylot's avatar Skylot

res: fix escape for apostrophes and quotes in string resources

parent 04246443
......@@ -123,4 +123,29 @@ public class StringUtils {
}
return sb.toString();
}
public static String escapeResStrValue(String str) {
int len = str.length();
StringBuilder sb = new StringBuilder(len);
for (int i = 0; i < len; i++) {
char c = str.charAt(i);
switch (c) {
case '&': sb.append("&amp;"); break;
case '<': sb.append("&lt;"); break;
case '>': sb.append("&gt;"); break;
case '"': sb.append("\\\""); break;
case '\'': sb.append("\\'"); break;
case '\n': sb.append("\\n"); break;
case '\r': sb.append("\\r"); break;
case '\t': sb.append("\\t"); break;
case '\b': sb.append("\\b"); break;
case '\f': sb.append("\\f"); break;
default:
sb.append(c);
break;
}
}
return sb.toString();
}
}
......@@ -105,7 +105,11 @@ public class ResXmlGen {
cw.add(' ').add(attrName).add("=\"").add(attrValue).add('"');
}
cw.add('>');
cw.add(StringUtils.escapeResValue(valueStr));
if (typeName.equals("string")) {
cw.add(StringUtils.escapeResStrValue(valueStr));
} else {
cw.add(StringUtils.escapeResValue(valueStr));
}
cw.add("</").add(typeName).add('>');
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment