@Test public void testUrlDecoder() { assertEquals(" ", resilientUrlDecode(" ")); assertEquals(" ", resilientUrlDecode(" %20")); assertEquals(" ", resilientUrlDecode("%20 ")); assertEquals(" ", resilientUrlDecode("%20%20")); assertEquals(" ", resilientUrlDecode("%u0020%u0020")); assertEquals(" ", resilientUrlDecode("%20%u0020")); assertEquals(" ", resilientUrlDecode("%u0020%20")); assertEquals("x ", resilientUrlDecode("x %2")); assertEquals("x ", resilientUrlDecode("x%20%2")); assertEquals("x 2", resilientUrlDecode("x%u202")); assertEquals("x ", resilientUrlDecode("x%u20")); assertEquals("x", resilientUrlDecode("x%u2")); assertEquals("x", resilientUrlDecode("x%u")); assertEquals("x", resilientUrlDecode("x%")); assertEquals(" ", resilientUrlDecode("%20 %20%u0020%20 %20%2")); }
public static String resilientUrlDecode(String input) { String cookedInput = input; if (cookedInput.indexOf('%') > -1) { cookedInput = CHOPPED_STANDARD.matcher(cookedInput).replaceAll(""); if (cookedInput.contains("%u")) { cookedInput = replaceString(cookedInput, "%u00", "%u"); cookedInput = VALID_NON_STANDARD.matcher(cookedInput).replaceAll("%$1"); cookedInput = CHOPPED_NON_STANDARD.matcher(cookedInput).replaceAll(""); } } try { return URLDecoder.decode(cookedInput, "UTF-8"); } catch (UnsupportedEncodingException e) { return null; } }
Utils { public static String resilientUrlDecode(String input) { String cookedInput = input; if (cookedInput.indexOf('%') > -1) { cookedInput = CHOPPED_STANDARD.matcher(cookedInput).replaceAll(""); if (cookedInput.contains("%u")) { cookedInput = replaceString(cookedInput, "%u00", "%u"); cookedInput = VALID_NON_STANDARD.matcher(cookedInput).replaceAll("%$1"); cookedInput = CHOPPED_NON_STANDARD.matcher(cookedInput).replaceAll(""); } } try { return URLDecoder.decode(cookedInput, "UTF-8"); } catch (UnsupportedEncodingException e) { return null; } } }
Utils { public static String resilientUrlDecode(String input) { String cookedInput = input; if (cookedInput.indexOf('%') > -1) { cookedInput = CHOPPED_STANDARD.matcher(cookedInput).replaceAll(""); if (cookedInput.contains("%u")) { cookedInput = replaceString(cookedInput, "%u00", "%u"); cookedInput = VALID_NON_STANDARD.matcher(cookedInput).replaceAll("%$1"); cookedInput = CHOPPED_NON_STANDARD.matcher(cookedInput).replaceAll(""); } } try { return URLDecoder.decode(cookedInput, "UTF-8"); } catch (UnsupportedEncodingException e) { return null; } } private  Utils(); }
Utils { public static String resilientUrlDecode(String input) { String cookedInput = input; if (cookedInput.indexOf('%') > -1) { cookedInput = CHOPPED_STANDARD.matcher(cookedInput).replaceAll(""); if (cookedInput.contains("%u")) { cookedInput = replaceString(cookedInput, "%u00", "%u"); cookedInput = VALID_NON_STANDARD.matcher(cookedInput).replaceAll("%$1"); cookedInput = CHOPPED_NON_STANDARD.matcher(cookedInput).replaceAll(""); } } try { return URLDecoder.decode(cookedInput, "UTF-8"); } catch (UnsupportedEncodingException e) { return null; } } private  Utils(); static String resilientUrlDecode(String input); static byte hexCharsToByte(String twoHexDigits); static byte hexCharsToByte(char c1, char c2); static String decodeApacheHTTPDLogValue(String input); static String makeHTMLEncodedInert(String uriString); static String replaceString(
        final String input,
        final String searchFor,
        final String replaceWith
    ); }
Utils { public static String resilientUrlDecode(String input) { String cookedInput = input; if (cookedInput.indexOf('%') > -1) { cookedInput = CHOPPED_STANDARD.matcher(cookedInput).replaceAll(""); if (cookedInput.contains("%u")) { cookedInput = replaceString(cookedInput, "%u00", "%u"); cookedInput = VALID_NON_STANDARD.matcher(cookedInput).replaceAll("%$1"); cookedInput = CHOPPED_NON_STANDARD.matcher(cookedInput).replaceAll(""); } } try { return URLDecoder.decode(cookedInput, "UTF-8"); } catch (UnsupportedEncodingException e) { return null; } } private  Utils(); static String resilientUrlDecode(String input); static byte hexCharsToByte(String twoHexDigits); static byte hexCharsToByte(char c1, char c2); static String decodeApacheHTTPDLogValue(String input); static String makeHTMLEncodedInert(String uriString); static String replaceString(
        final String input,
        final String searchFor,
        final String replaceWith
    );  }