List of utility methods to do String Sanitize
String | sanitizeForJson(String data) Sanitize a string for inclusion in a JSON string Because most browsers will interpret HTML tags e.g. data = data.replace("<", "\\x3C"); data = data.replace(">", "\\x3E"); data = data.replace("\u2028", ""); return data; |
String | sanitizeForLogMessage(String unsanitizedString) Sanitizes the log message, only allow br element and span element with class attribute equals to "bold" or "text-danger". if (unsanitizedString == null) { return null; return unsanitizedString.replaceAll("<(?!(/?(span( class=\"(bold|text-danger)\")?|br)>))", "<") .replaceAll("(?<!(</?(span( class=\"(bold|text-danger)\")?|br)))>", ">") .replaceAll("(?<!<span class=(\"(bold|text-danger))?)\"(?!>)", """) .replaceAll("(?<!<)/(?!(span|br)>)", "/").replace("'", "'") .replaceAll("&(?!(amp;)|(lt;)|(gt;)|(quot;)|(#x2f;)|(#39;))", "&"); ... |
String | sanitizeForSearch(String str) Sanitize the string for searching. if (str == null) { return null; return str .replace("`", " ").replace("!", " ").replace("#", " ").replace("$", " ").replace("%", " ") .replace("^", " ").replace("&", " ").replace("[", " ").replace("]", " ").replace("{", " ") .replace("}", " ").replace("|", " ").replace(";", " ").replace("*", " ").replace(".", " ") .replace("?", " ").replace("'", " ").replace("/", " ") ... |
String | sanitizeForSemgrexName(String text) Sanitizes the given string into a Semgrex friendly name text = text.replaceAll("\\.", "_DOT_"); text = text.replaceAll("\\,", "_COMMA_"); text = text.replaceAll("\\\\", "_BSLASH_"); text = text.replaceAll("\\/", "_BSLASH_"); text = text.replaceAll("\\?", "_QUES_"); text = text.replaceAll("\\!", "_BANG_"); text = text.replaceAll("\\$", "_DOL_"); text = text.replaceAll("\\!", "_BANG_"); ... |
String | sanitizeForTableName(String input) Strips illegal characters so that the given string can be used as a SQLite table name. return input.replaceAll("[^A-Za-z0-9]", ""); |
String | sanitizeForUri(String uri, String replace) Sanitizes a URI to conform with the URI standards RFC3986 http://www.ietf.org/rfc/rfc3986.txt. uri = uri.replaceAll("[^a-zA-Z0-9\\._-]+", replace); return uri; |
String | sanitizeFullPrefixKey(String propKey) sanitize Full Prefix Key return propKey + STRIP_SUFFIX;
|
String | sanitizeGoogleId(String rawGoogleId) Sanitizes a google ID by removing leading/trailing whitespace and the trailing "@gmail.com". if (rawGoogleId == null) { return null; String sanitized = rawGoogleId.trim(); if (sanitized.toLowerCase().endsWith("@gmail.com")) { sanitized = sanitized.split("@")[0]; return sanitized.trim(); ... |
String | sanitizeHeader(String header) sanitize Header if (header == null) return null; final char[] chars = header.toCharArray(); for (int i = 0, j = chars.length; i < j; i++) { if (!isAsciiPrintable(chars[i])) { chars[i] = '.'; return new String(chars); |
String | sanitizeID(String name) sanitize ID name = name.replaceAll("[^a-zA-Z0-9_\\-\\.]", "_"); if (name.matches("([0-9]|\\.|\\-).*")) name = "a" + name; return name; |