@Test public void encode_nullString_returnsNullIfStringIsNull() { assertNull(SecurityUtils.encode(null)); }
public static String encode(String s) { if (s == null) { return null; } int sz = s.length(); StringBuffer buffer = new StringBuffer(); for (int i = 0; i < sz; i++) { char ch = s.charAt(i); if (ch > 0xfff) { buffer.append("\\u" + Integer.toHexString(ch).toUpperCase(Locale.ENGLISH)); } else if (ch > 0xff) { buffer.append("\\u0" + Integer.toHexString(ch).toUpperCase(Locale.ENGLISH)); } else if (ch > 0x7f) { buffer.append("\\u00" + Integer.toHexString(ch).toUpperCase(Locale.ENGLISH)); } else if (ch < 32) { switch (ch) { case '\b': buffer.append('\\'); buffer.append('b'); break; case '\n': buffer.append('\\'); buffer.append('n'); break; case '\t': buffer.append('\\'); buffer.append('t'); break; case '\f': buffer.append('\\'); buffer.append('f'); break; case '\r': buffer.append('\\'); buffer.append('r'); break; default: if (ch > 0xf) { buffer.append("\\u00" + Integer.toHexString(ch).toUpperCase(Locale.ENGLISH)); } else { buffer.append("\\u000" + Integer.toHexString(ch).toUpperCase(Locale.ENGLISH)); } break; } } else { switch (ch) { case '\'': buffer.append('\''); break; case '"': buffer.append('\\'); buffer.append('"'); break; case '\\': buffer.append('\\'); buffer.append('\\'); break; case '/': buffer.append('/'); break; default: buffer.append(ch); break; } } } return buffer.toString(); }
SecurityUtils { public static String encode(String s) { if (s == null) { return null; } int sz = s.length(); StringBuffer buffer = new StringBuffer(); for (int i = 0; i < sz; i++) { char ch = s.charAt(i); if (ch > 0xfff) { buffer.append("\\u" + Integer.toHexString(ch).toUpperCase(Locale.ENGLISH)); } else if (ch > 0xff) { buffer.append("\\u0" + Integer.toHexString(ch).toUpperCase(Locale.ENGLISH)); } else if (ch > 0x7f) { buffer.append("\\u00" + Integer.toHexString(ch).toUpperCase(Locale.ENGLISH)); } else if (ch < 32) { switch (ch) { case '\b': buffer.append('\\'); buffer.append('b'); break; case '\n': buffer.append('\\'); buffer.append('n'); break; case '\t': buffer.append('\\'); buffer.append('t'); break; case '\f': buffer.append('\\'); buffer.append('f'); break; case '\r': buffer.append('\\'); buffer.append('r'); break; default: if (ch > 0xf) { buffer.append("\\u00" + Integer.toHexString(ch).toUpperCase(Locale.ENGLISH)); } else { buffer.append("\\u000" + Integer.toHexString(ch).toUpperCase(Locale.ENGLISH)); } break; } } else { switch (ch) { case '\'': buffer.append('\''); break; case '"': buffer.append('\\'); buffer.append('"'); break; case '\\': buffer.append('\\'); buffer.append('\\'); break; case '/': buffer.append('/'); break; default: buffer.append(ch); break; } } } return buffer.toString(); } }
SecurityUtils { public static String encode(String s) { if (s == null) { return null; } int sz = s.length(); StringBuffer buffer = new StringBuffer(); for (int i = 0; i < sz; i++) { char ch = s.charAt(i); if (ch > 0xfff) { buffer.append("\\u" + Integer.toHexString(ch).toUpperCase(Locale.ENGLISH)); } else if (ch > 0xff) { buffer.append("\\u0" + Integer.toHexString(ch).toUpperCase(Locale.ENGLISH)); } else if (ch > 0x7f) { buffer.append("\\u00" + Integer.toHexString(ch).toUpperCase(Locale.ENGLISH)); } else if (ch < 32) { switch (ch) { case '\b': buffer.append('\\'); buffer.append('b'); break; case '\n': buffer.append('\\'); buffer.append('n'); break; case '\t': buffer.append('\\'); buffer.append('t'); break; case '\f': buffer.append('\\'); buffer.append('f'); break; case '\r': buffer.append('\\'); buffer.append('r'); break; default: if (ch > 0xf) { buffer.append("\\u00" + Integer.toHexString(ch).toUpperCase(Locale.ENGLISH)); } else { buffer.append("\\u000" + Integer.toHexString(ch).toUpperCase(Locale.ENGLISH)); } break; } } else { switch (ch) { case '\'': buffer.append('\''); break; case '"': buffer.append('\\'); buffer.append('"'); break; case '\\': buffer.append('\\'); buffer.append('\\'); break; case '/': buffer.append('/'); break; default: buffer.append(ch); break; } } } return buffer.toString(); }  }
SecurityUtils { public static String encode(String s) { if (s == null) { return null; } int sz = s.length(); StringBuffer buffer = new StringBuffer(); for (int i = 0; i < sz; i++) { char ch = s.charAt(i); if (ch > 0xfff) { buffer.append("\\u" + Integer.toHexString(ch).toUpperCase(Locale.ENGLISH)); } else if (ch > 0xff) { buffer.append("\\u0" + Integer.toHexString(ch).toUpperCase(Locale.ENGLISH)); } else if (ch > 0x7f) { buffer.append("\\u00" + Integer.toHexString(ch).toUpperCase(Locale.ENGLISH)); } else if (ch < 32) { switch (ch) { case '\b': buffer.append('\\'); buffer.append('b'); break; case '\n': buffer.append('\\'); buffer.append('n'); break; case '\t': buffer.append('\\'); buffer.append('t'); break; case '\f': buffer.append('\\'); buffer.append('f'); break; case '\r': buffer.append('\\'); buffer.append('r'); break; default: if (ch > 0xf) { buffer.append("\\u00" + Integer.toHexString(ch).toUpperCase(Locale.ENGLISH)); } else { buffer.append("\\u000" + Integer.toHexString(ch).toUpperCase(Locale.ENGLISH)); } break; } } else { switch (ch) { case '\'': buffer.append('\''); break; case '"': buffer.append('\\'); buffer.append('"'); break; case '\\': buffer.append('\\'); buffer.append('\\'); break; case '/': buffer.append('/'); break; default: buffer.append(ch); break; } } } return buffer.toString(); }  static boolean isValidPort(String port); static boolean isValidScheme(String scheme); static boolean isValidHost(String host, String apiId, String region); static String crlf(String s); static String encode(String s); static String getValidFilePath(String inputPath); @SuppressFBWarnings("PATH_TRAVERSAL_IN") static String getValidFilePath(final String inputPath, boolean isWrite); }
SecurityUtils { public static String encode(String s) { if (s == null) { return null; } int sz = s.length(); StringBuffer buffer = new StringBuffer(); for (int i = 0; i < sz; i++) { char ch = s.charAt(i); if (ch > 0xfff) { buffer.append("\\u" + Integer.toHexString(ch).toUpperCase(Locale.ENGLISH)); } else if (ch > 0xff) { buffer.append("\\u0" + Integer.toHexString(ch).toUpperCase(Locale.ENGLISH)); } else if (ch > 0x7f) { buffer.append("\\u00" + Integer.toHexString(ch).toUpperCase(Locale.ENGLISH)); } else if (ch < 32) { switch (ch) { case '\b': buffer.append('\\'); buffer.append('b'); break; case '\n': buffer.append('\\'); buffer.append('n'); break; case '\t': buffer.append('\\'); buffer.append('t'); break; case '\f': buffer.append('\\'); buffer.append('f'); break; case '\r': buffer.append('\\'); buffer.append('r'); break; default: if (ch > 0xf) { buffer.append("\\u00" + Integer.toHexString(ch).toUpperCase(Locale.ENGLISH)); } else { buffer.append("\\u000" + Integer.toHexString(ch).toUpperCase(Locale.ENGLISH)); } break; } } else { switch (ch) { case '\'': buffer.append('\''); break; case '"': buffer.append('\\'); buffer.append('"'); break; case '\\': buffer.append('\\'); buffer.append('\\'); break; case '/': buffer.append('/'); break; default: buffer.append(ch); break; } } } return buffer.toString(); }  static boolean isValidPort(String port); static boolean isValidScheme(String scheme); static boolean isValidHost(String host, String apiId, String region); static String crlf(String s); static String encode(String s); static String getValidFilePath(String inputPath); @SuppressFBWarnings("PATH_TRAVERSAL_IN") static String getValidFilePath(final String inputPath, boolean isWrite);  }