StringHelper { public static final String escapeHtml(String str) { return StringEscapeUtils.escapeHtml(str); }  static List<String> getParts(String in, String delim); static String formatLocaleDate(long date, Locale locale); static String formatLocaleDateFull(long date, Locale locale); static String formatLocaleDateTime(long date, Locale locale); static String formatLocaleTime(long time, Locale locale); static String formatMemory(long mem); static String formatFloat(float f, int fractionDigits); static String urlEncodeISO88591(String url); static String urlEncodeUTF8(String url); static String[] getMapKeysAsStringArray(Map m); static String[] getMapValuesAsStringArray(Map m); static boolean containsNoneOfCoDouSemi(String s); static boolean containsNonWhitespace(String s); static String stripLineBreaks(String cellValue); static String convertLineBreaksToHTML(String plainText); static String transformDisplayNameToFileSystemName(String s); static String check4xMacRoman(String extractedCharset); static String formatAsCSVString(Set<String> entries); static String formatAsCSVString(List<String> entries); static String formatAsSortUniqCSVString(List<String> s); static String formatAsSortUniqCSVString(Set<String> s); static final String escapeHtml(String str); static final void escapeHtml(Writer writer, String str); static final String escapeJavaScript(String str); static final String escapeHtmlAttribute(String str); static final String escapeXml(String str); static final String unescapeHtml(String str); static final String ALL_WITHOUT_COMMA_2POINT_STRPNT; }
@Test public void escapeHtml() { String badString = "<script>alert('XSS');</script>"; String escapedString = StringHelper.escapeHtml(badString); assertTrue(escapedString.indexOf("<script>") == -1); assertTrue(escapedString.indexOf("&lt") != -1); }
@Test public void escapeHtml_umlauts() { String anyString = "für"; String escapedString = StringHelper.escapeHtml(anyString); System.out.println("anyString: " + anyString); System.out.println("escapedString: " + escapedString); assertTrue(escapedString.indexOf("&uuml;") != -1); }