StringUtils { public static String escapeJavaScript(String string) { if (string == null) { return null; } StringBuilder sb = new StringBuilder(); for (int i = 0, s = string.length(); i < s; ++ i) { char c = string.charAt(i); if (0x30 <= c && c <= 0x39 || 0x41 <= c && c <= 0x5A || 0x61 <= c && c <= 0x7A) { sb.append(c); } else { String hex = Integer.toHexString(c); int hexLen = hex.length(); if (c < 256) { sb.append("\\x").append("00".substring(hexLen)); } else { sb.append("\\u").append("0000".substring(hexLen)); } sb.append(hex); } } return sb.toString(); }  @Deprecated static T fromString(Class<T> returnType, String... strings); static String toDelimited(String string, String delimiter); static String toHyphenated(String string); static String toUnderscored(String string); static String toPascalCase(String string); static String toCamelCase(String string); static String toLabel(String string); static String toNormalized(CharSequence string); static String[] fromCsv(String string); static String toCsv(String... strings); static String escapeHtmlAndBreak(String string, int maxWordLength); static String escapeHtmlAndBreak(String string); static String hex(byte[] bytes); static byte[] hash(String algorithm, String string); static byte[] md5(String string); static byte[] sha1(String string); static byte[] sha512(String string); static byte[] hmac(String algorithm, String key, String string); static byte[] hmacSha1(String key, String string); static String encodeUri(String string); static String decodeUri(String string); static String addQueryParameters(String uri, Object... parameters); static String getQueryParameterValue(String uri, String name); static List<String> getQueryParameterValues(String uri, String name); static Map<String, List<String>> getQueryParameterMap(String url); @Deprecated static String transformUri(String uri, Object... parameters); @Deprecated static String getParameter(String uri, String name); @Deprecated static String[] getParameterValues(String uri, String name); static Pattern getPattern(String pattern); static Matcher getMatcher(CharSequence string, String pattern); static MatchResult getMatcherResult(CharSequence string, String pattern); static boolean matches(CharSequence string, String pattern); static boolean matchAll(CharSequence string, String... patterns); static boolean matchAny(CharSequence string, String... patterns); static int matchCount(CharSequence string, String... patterns); static String replaceAll(CharSequence string, String pattern, String replacement); static String replaceAll(CharSequence string, String pattern, String replacement, String... more); static String removeAll(CharSequence string, CharSequence pattern); static String[] split(CharSequence string, String pattern, int limit); static String[] split(CharSequence string, String pattern); static String escapeCsv(String string); static String escapeHtml(String string); static String escapeJava(String string); static String escapeJavaScript(String string); static String escapeQuotes(String string); static String escapeSql(String string); static String escapeXml(String string); static String unescapeCsv(String string); static String unescapeHtml(String string); static String unescapeJava(String string); static String unescapeJavaScript(String string); static String unescapeXml(String string); static String join(List<String> strings, String delimiter); static String join(String[] strings, String delimiter); static boolean isEmpty(String string); static boolean isBlank(String string); static boolean equals(String str1, String str2); static boolean equalsIgnoreCase(String str1, String str2); static String stripHtml(CharSequence sequence); static String ensureStart(String string, String delimiter); static String ensureEnd(String string, String delimiter); static String ensureSurrounding(String string, String delimiter); static String removeStart(String string, String delimiter); static String removeEnd(String string, String delimiter); static String removeSurrounding(String string, String delimiter); static String getPathInfo(String path, String servletPath); static String toLowerCaseAscii(String string); static String trimAndCollapseWhitespaces(String string); static String getFileName(String filePath); @Deprecated
    static final Charset US_ASCII; @Deprecated
    static final Charset ISO_8859_1; @Deprecated
    static final Charset UTF_8; @Deprecated
    static final Charset UTF_16BE; @Deprecated
    static final Charset UTF_16LE; @Deprecated
    static final Charset UTF_16; }
@Test public void escapeJavaScript_null() { assertEquals(null, StringUtils.escapeJavaScript(null)); }
@Test public void escapeJavaScript_blank() { assertEquals("", StringUtils.escapeJavaScript("")); }
@Test public void escapeJavaScript_noescaped() { assertEquals("abcdef", StringUtils.escapeJavaScript("abcdef")); }
@Test public void escapeJavaScript_space() { assertEquals("abc\\x20def", StringUtils.escapeJavaScript("abc def")); }
@Test public void escapeJavaScript_quote() { assertEquals("abc\\x27def", StringUtils.escapeJavaScript("abc'def")); }
@Test public void escapeJavaScript_dquote() { assertEquals("abc\\x22def", StringUtils.escapeJavaScript("abc\"def")); }
@Test public void escapeJavaScript_amp() { assertEquals("abc\\x26def", StringUtils.escapeJavaScript("abc&def")); }
@Test public void escapeJavaScript_ltgt() { assertEquals("abc\\x3cdef\\x3e", StringUtils.escapeJavaScript("abc<def>")); }
@Test public void escapeJavaScript_usecase_1() { String message = "\" onmouseover=alert(1) "; assertEquals("\\x22\\x20onmouseover\\x3dalert\\x281\\x29\\x20", StringUtils.escapeJavaScript(message)); }