strip down utf8 4-byte characters

This commit is contained in:
Athou
2013-04-21 18:38:28 +02:00
parent 0f5cb77502
commit 1f15cabfa5

View File

@@ -102,6 +102,7 @@ public class FeedUpdateService {
private String handleContent(String content) {
if (StringUtils.isNotBlank(content)) {
content = trimUnicodeSurrogateCharacters(content);
Whitelist whitelist = Whitelist.relaxed();
whitelist.addEnforcedAttribute("a", "target", "_blank");
@@ -114,4 +115,15 @@ public class FeedUpdateService {
}
return content;
}
private String trimUnicodeSurrogateCharacters(String text) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < text.length(); i++) {
char ch = text.charAt(i);
if (!Character.isHighSurrogate(ch) && !Character.isLowSurrogate(ch)) {
sb.append(ch);
}
}
return sb.toString();
}
}