CookieDataCodec { public static void decode(Map<String, String> map, String data) throws UnsupportedEncodingException { String[] keyValues = data.split("&"); for (String keyValue : keyValues) { String[] splitted = keyValue.split("=", 2); if (splitted.length == 2) { map.put(URLDecoder.decode(splitted[0], "utf-8"), URLDecoder.decode(splitted[1], "utf-8")); } } }  static void decode(Map<String, String> map, String data); static String encode(Map<String, String> map); static boolean safeEquals(String a, String b);  }
@Test public void decode_values_of_the_previously_supported_format() throws UnsupportedEncodingException { final Map<String, String> inMap = new HashMap<String, String>(2); inMap.put("a", "b"); inMap.put("c", "d"); final String data = oldEncoder(inMap); final Map<String, String> outMap = new HashMap<String, String>(0); decode(outMap, data); assertEquals(0, outMap.size()); }
@Test public void decode_values_of_the_previously_supported_format_with_the_new_delimiters_in_them() throws UnsupportedEncodingException { final Map<String, String> inMap = new HashMap<String, String>(1); inMap.put("a", "b&="); final String data = oldEncoder(inMap); final Map<String, String> outMap = new HashMap<String, String>(0); decode(outMap, data); assertEquals(0, outMap.size()); }
@Test public void decode_values_with_gibberish_in_them() throws UnsupportedEncodingException { final String data = "asfjdlkasjdflk"; final Map<String, String> outMap = new HashMap<String, String>(1); decode(outMap, data); assertEquals(0, outMap.size()); }