UrlMatcherImpl implements UrlMatcher { public static Map<String, String> splitQuery(String query) { if (query == null) { return null; } String[] params = query.split("&"); Map<String, String> map = new HashMap<>(); for (String param : params) { String[] paramPair = param.split("="); if (paramPair.length < 1) { continue; } String name = paramPair[0]; String value = paramPair.length == 2 ? paramPair[1] : null; try { name = URLDecoder.decode(name, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } try { value = value == null ? null : URLDecoder.decode(value, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } map.put(name, value); } return map; }  @Override void addCompiledRoute(CompiledRoute route); Request match(String urlStr); static Map<String, String> splitQuery(String query);  }
@Test public void testSplitQuery() { Map<String, String> query = UrlMatcherImpl.splitQuery("foo=bar"); assertEquals("-> assert query string parser with 1 param", 1, query.size()); assertEquals("-> assert query string parser with 1 param", "bar", query.get("foo")); Map<String, String> query1 = UrlMatcherImpl.splitQuery("foo=bar&foo2=bar2&foo3=bar3"); assertEquals("-> assert query string parser with 3 params", 3, query1.size()); assertEquals("-> assert query string parser with 3 param", "bar", query1.get("foo")); assertEquals("-> assert query string parser with 3 param", "bar2", query1.get("foo2")); assertEquals("-> assert query string parser with 3 param", "bar3", query1.get("foo3")); Map<String, String> query2 = UrlMatcherImpl.splitQuery("foo=bar&foo2=bar2&chinese=%e4%b8%ad%e6%96%87333%e6%b5%8b%e8%af%95"); assertEquals("-> assert query string parser with 3 params", 3, query2.size()); assertEquals("-> assert query string parser with 3 param", "bar", query2.get("foo")); assertEquals("-> assert query string parser with 3 param", "bar2", query2.get("foo2")); assertEquals("-> assert query string parser with 3 param", "中文333测试", query2.get("chinese")); }