2016-11-25 48 views
0

爲什麼URI#getQuery()未能解碼非法字符

new URI(
    null, 
    null, 
    "/monitor/123456/data", 
    "filterParams=[{\"id\":12,\"type\":\"dimension\"}]", 
    null).getQuery() 

返回

filterParams = [%7B%22id%22:12,%22type%22:%22dimension%22% 7D]

和不

「filterParams = [{\」 ID \ 「:12,\」 類型\「:\ 「尺寸\」}]」

根據URI#getQuery()文檔

此方法返回的字符串是等於由除了逃脫八位組的所有序列進行解碼的#getRawQuery()方法返回。

是JDK bug還是我在這裏丟失了一些理解?

回答

0

根據上面的註釋私人方法URI.decode它不是一個錯誤,但功能:)。

/* 
Evaluates all escapes in s, applying UTF-8 decoding if needed. Assumes 
that escapes are well-formed syntactically, i.e., of the form %XX. If a 
sequence of escaped octets is not valid UTF-8 then the erroneous octets 
are replaced with '\uFFFD'. 
Exception: any "%" found between "[]" is left alone. It is an IPv6 literal with a scope_id 
*/ 
private static String decode(String s) {...}