UriComponent { public static MultivaluedMap<String, String> parseQueryString(String rawQuery, boolean decode) { MultivaluedMap<String, String> result = new MultivaluedMapImpl(); if (!(rawQuery == null || rawQuery.isEmpty())) { int p = 0; int n = 0; while (n < rawQuery.length()) { n = rawQuery.indexOf('&', p); if (n < 0) { n = rawQuery.length(); } String pair = rawQuery.substring(p, n); if (!pair.isEmpty()) { String name; String value; int eq = pair.indexOf('='); if (eq < 0) { name = pair; value = ""; } else { name = pair.substring(0, eq); value = pair.substring(eq + 1); } result.add(decode ? decode(name, QUERY) : name, decode ? decode(value, QUERY) : value); } p = n + 1; } } return result; } private  UriComponent(); static URI normalize(URI uri); static String encode(String str, int component, boolean containsUriParams); static String validateUriComponent(String str, int component, boolean containsUriParams); static boolean isUriComponentContainsValidCharacters(int component, String str); static String recognizeEncode(String str, int component, boolean containsUriParams); static String decode(String str, int component); static boolean checkHexCharacters(String s, int p); static List<PathSegment> parsePathSegments(String path, boolean decode); static MultivaluedMap<String, String> parseQueryString(String rawQuery, boolean decode); static URI resolve(URI baseUri, URI resolvingUri); static final int SCHEME; static final int USER_INFO; static final int HOST; static final int PORT; static final int PATH_SEGMENT; static final int PATH; static final int QUERY; static final int FRAGMENT; static final int SSP; static final int MATRIX_PARAM; static final int QUERY_STRING; static final String PERCENT; }
@Test public void parsesQueryString() { String queryString = "q1=to%20be%20or%20not%20to%20be&q2=foo&q2=%D0%9F%D1%80%D0%B8%D0%B2%D1%96%D1%82"; MultivaluedMapImpl expected = new MultivaluedMapImpl(); expected.add("q1", "to%20be%20or%20not%20to%20be"); expected.add("q2", "foo"); expected.add("q2", "%D0%9F%D1%80%D0%B8%D0%B2%D1%96%D1%82"); MultivaluedMap<String, String> result = parseQueryString(queryString, false); assertEquals(expected, result); }
@Test public void parsesAndDecodeQueryString() { String queryString = "q1=to%20be%20or%20not%20to%20be&q2=foo&q2=%D0%9F%D1%80%D0%B8%D0%B2%D1%96%D1%82"; MultivaluedMapImpl expected = new MultivaluedMapImpl(); expected.add("q1", "to be or not to be"); expected.addAll("q2", "foo", "\u041f\u0440\u0438\u0432\u0456\u0442"); MultivaluedMap<String, String> result = parseQueryString(queryString, true); assertEquals(expected, result); }
@Test public void parsesQueryString_EVERREST_58() { String str = "q1=bar&&q2=foo&q2=test"; MultivaluedMapImpl expected = new MultivaluedMapImpl(); expected.add("q1", "bar"); expected.addAll("q2", "foo", "test"); MultivaluedMap<String, String> result = parseQueryString(str, false); assertEquals(expected, result); result = parseQueryString(str, true); assertEquals(expected, result); }