UrlEscapeUtils { public static String escape(String str) { Utils.checkNotNull(str, "str == null"); int slen = str.length(); for (int index = 0; index < slen; index++) { char c = str.charAt(index); if (c >= SAFE_OCTETS.length || !SAFE_OCTETS[c]) { return escapeSlow(str, index); } } return str; } private  UrlEscapeUtils(); static String escape(String str);  }
@Test public void actsAsUrlFormParameterEscaper() { try { UrlEscapeUtils.escape(null); fail("Escaping null string should throw exception"); } catch (NullPointerException x) { } assertUnescaped('a'); assertUnescaped('z'); assertUnescaped('A'); assertUnescaped('Z'); assertUnescaped('0'); assertUnescaped('9'); assertUnescaped('-'); assertUnescaped('_'); assertUnescaped('.'); assertUnescaped('*'); assertEscaping("%3D", '='); assertEscaping("%2F", '/'); assertEscaping("%00", '\u0000'); assertEscaping("%7F", '\u007f'); assertEscaping("%C2%80", '\u0080'); assertEscaping("%DF%BF", '\u07ff'); assertEscaping("%E0%A0%80", '\u0800'); assertEscaping("%EF%BF%BF", '\uffff'); assertUnicodeEscaping("%F0%90%80%80", '\uD800', '\uDC00'); assertUnicodeEscaping("%F4%8F%BF%BF", '\uDBFF', '\uDFFF'); assertThat(UrlEscapeUtils.escape("")).isEqualTo(""); assertThat(UrlEscapeUtils.escape("safestring")).isEqualTo("safestring"); assertThat(UrlEscapeUtils.escape("embedded\0null")).isEqualTo("embedded%00null"); assertThat(UrlEscapeUtils.escape("max\uffffchar")).isEqualTo("max%EF%BF%BFchar"); assertEscaping("%21", '!'); assertEscaping("%28", '('); assertEscaping("%29", ')'); assertEscaping("%7E", '~'); assertEscaping("%27", '\''); assertEscaping("%20", ' '); assertEscaping("%2B", '+'); assertThat(UrlEscapeUtils.escape("safe with spaces")).isEqualTo("safe%20with%20spaces"); assertThat(UrlEscapeUtils.escape("foo@bar.com")).isEqualTo("foo%40bar.com"); }