@Test public void escapePotentialMaliciousCharsInTxt_strDoesContainMaliciousChars_maliciousCharsEscaped() throws UnsupportedEncodingException { final String str = EncodingUtils.POTENTIAL_MALICIOUS_CHARS; final String expectedStr = "%3f%21%40%2e%2f%23%25%5e%2a%28%29%5f%3d%7e%2b%7b%7d"; String result = EncodingUtils.escapePotentialMaliciousCharsInTxt(str); assertEquals(expectedStr, result); }
public static String escapePotentialMaliciousCharsInTxt(@NotNull String str) throws UnsupportedEncodingException { StringBuilder sb = new StringBuilder(); for (int i = 0; i < str.length(); i++) { char ch = str.charAt(i); if (POTENTIAL_MALICIOUS_CHARS.contains(String.valueOf(ch))) { sb.append('%').append(Integer.toHexString(ch)); } else { sb.append(ch); } } return sb.toString(); }
EncodingUtils { public static String escapePotentialMaliciousCharsInTxt(@NotNull String str) throws UnsupportedEncodingException { StringBuilder sb = new StringBuilder(); for (int i = 0; i < str.length(); i++) { char ch = str.charAt(i); if (POTENTIAL_MALICIOUS_CHARS.contains(String.valueOf(ch))) { sb.append('%').append(Integer.toHexString(ch)); } else { sb.append(ch); } } return sb.toString(); } }
EncodingUtils { public static String escapePotentialMaliciousCharsInTxt(@NotNull String str) throws UnsupportedEncodingException { StringBuilder sb = new StringBuilder(); for (int i = 0; i < str.length(); i++) { char ch = str.charAt(i); if (POTENTIAL_MALICIOUS_CHARS.contains(String.valueOf(ch))) { sb.append('%').append(Integer.toHexString(ch)); } else { sb.append(ch); } } return sb.toString(); } private  EncodingUtils(); }
EncodingUtils { public static String escapePotentialMaliciousCharsInTxt(@NotNull String str) throws UnsupportedEncodingException { StringBuilder sb = new StringBuilder(); for (int i = 0; i < str.length(); i++) { char ch = str.charAt(i); if (POTENTIAL_MALICIOUS_CHARS.contains(String.valueOf(ch))) { sb.append('%').append(Integer.toHexString(ch)); } else { sb.append(ch); } } return sb.toString(); } private  EncodingUtils(); static String discardBOMChar(@NotNull String str); static String toUTF8(@NotNull String str, @NotNull String crtEncoding); static String escapePotentialMaliciousCharsInTxt(@NotNull String str); static String escapePotentialMaliciousCharsInXml(@NotNull String str); }
EncodingUtils { public static String escapePotentialMaliciousCharsInTxt(@NotNull String str) throws UnsupportedEncodingException { StringBuilder sb = new StringBuilder(); for (int i = 0; i < str.length(); i++) { char ch = str.charAt(i); if (POTENTIAL_MALICIOUS_CHARS.contains(String.valueOf(ch))) { sb.append('%').append(Integer.toHexString(ch)); } else { sb.append(ch); } } return sb.toString(); } private  EncodingUtils(); static String discardBOMChar(@NotNull String str); static String toUTF8(@NotNull String str, @NotNull String crtEncoding); static String escapePotentialMaliciousCharsInTxt(@NotNull String str); static String escapePotentialMaliciousCharsInXml(@NotNull String str);  }