mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix code
This commit is contained in:
parent
62113aa1b0
commit
bd5160e8d0
@ -134,11 +134,6 @@ public class URLDecoder implements Serializable {
|
||||
char c;
|
||||
for (int i = 0; i < length; i++) {
|
||||
c = str.charAt(i);
|
||||
if(CharUtil.PLUS == c){
|
||||
result.append(isPlusToSpace ? CharUtil.SPACE : c);
|
||||
begin++;
|
||||
continue;
|
||||
}
|
||||
if(ESCAPE_CHAR == c || CharUtil.isHexChar(c)){
|
||||
continue;
|
||||
}
|
||||
@ -150,6 +145,10 @@ public class URLDecoder implements Serializable {
|
||||
}
|
||||
|
||||
// 非Hex字符,忽略本字符
|
||||
if(CharUtil.PLUS == c && isPlusToSpace){
|
||||
c = CharUtil.SPACE;
|
||||
}
|
||||
|
||||
result.append(c);
|
||||
begin = i + 1;
|
||||
}
|
||||
|
@ -51,14 +51,14 @@ class UrlDecoderTest {
|
||||
@Test
|
||||
void decodeCharSetIsNullToStrTest() {
|
||||
final String hello = "你好";
|
||||
String decode = URLDecoder.decode(hello, null, true);
|
||||
final String decode = URLDecoder.decode(hello, null, true);
|
||||
Assertions.assertEquals(hello, decode);
|
||||
}
|
||||
|
||||
@Test
|
||||
void decodeStrIsEmptyToStrTest() {
|
||||
final String strEmpty = "";
|
||||
String decode = URLDecoder.decode(strEmpty, StandardCharsets.UTF_8, true);
|
||||
final String decode = URLDecoder.decode(strEmpty, StandardCharsets.UTF_8, true);
|
||||
Assertions.assertEquals(strEmpty, decode);
|
||||
}
|
||||
|
||||
@ -66,19 +66,19 @@ class UrlDecoderTest {
|
||||
void decodeStrWithUTF8ToStrTest() {
|
||||
final String exceptedDecode = "你好";
|
||||
final String encode = "%E4%BD%A0%E5%A5%BD";
|
||||
String s1 = URLDecoder.decode(encode);
|
||||
final String s1 = URLDecoder.decode(encode);
|
||||
Assertions.assertEquals(exceptedDecode, s1);
|
||||
|
||||
String s2 = URLDecoder.decode(encode, StandardCharsets.UTF_8);
|
||||
final String s2 = URLDecoder.decode(encode, StandardCharsets.UTF_8);
|
||||
Assertions.assertEquals(exceptedDecode, s2);
|
||||
|
||||
String s3 = URLDecoder.decode(encode, true);
|
||||
final String s3 = URLDecoder.decode(encode, true);
|
||||
Assertions.assertEquals(exceptedDecode, s3);
|
||||
|
||||
String s4 = URLDecoder.decode(encode + "+", false);
|
||||
final String s4 = URLDecoder.decode(encode + "+", false);
|
||||
Assertions.assertEquals(exceptedDecode + "+", s4);
|
||||
|
||||
String s5 = URLDecoder.decode(encode, StandardCharsets.UTF_8, false);
|
||||
final String s5 = URLDecoder.decode(encode, StandardCharsets.UTF_8, false);
|
||||
Assertions.assertEquals(exceptedDecode, s5);
|
||||
}
|
||||
|
||||
@ -86,10 +86,10 @@ class UrlDecoderTest {
|
||||
void decodeStrWithUTF8ToByteTest(){
|
||||
final String exceptedDecode = "你好";
|
||||
final String encode = "%E4%BD%A0%E5%A5%BD";
|
||||
byte[] decode = URLDecoder.decode(encode.getBytes(StandardCharsets.UTF_8));
|
||||
final byte[] decode = URLDecoder.decode(encode.getBytes(StandardCharsets.UTF_8));
|
||||
Assertions.assertEquals(exceptedDecode, new String(decode,StandardCharsets.UTF_8));
|
||||
|
||||
byte[] decode1 = URLDecoder.decode((encode + "+").getBytes(StandardCharsets.UTF_8));
|
||||
final byte[] decode1 = URLDecoder.decode((encode + "+").getBytes(StandardCharsets.UTF_8));
|
||||
Assertions.assertEquals(exceptedDecode+" ",new String(decode1,StandardCharsets.UTF_8));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user