1. 程式人生 > >URLDecoder: Illegal hex characters in escape (%) pattern - For input string

URLDecoder: Illegal hex characters in escape (%) pattern - For input string

esc ++ 原來 bstr parse () exce integer inpu

原因:後臺發布文章的時候,內容裏面有%,導致後臺URLDecoder.decode()轉碼的時候報錯。

看了java.net.URLDecoderdecode()的源碼,原來是轉碼錯誤。

貼出部分代碼,意思是取%後面的兩位,從16進制轉成10進制,要是轉碼錯誤就會報出這個異常。

while ( ((i+2) < numChars) && (c==‘%‘)) {
    int v = Integer.parseInt(s.substring(i+1,i+3),16);
    if (v < 0)
        throw new IllegalArgumentException("URLDecoder: Illegal hex characters in escape (%) pattern - negative value"
); bytes[pos++] = (byte) v; i+= 3; if (i < numChars) c = s.charAt(i); }

URLDecoder: Illegal hex characters in escape (%) pattern - For input string