This commit is contained in:
Looly 2022-04-30 11:40:20 +08:00
parent c9064c2334
commit 8b98cb3e90

View File

@ -1,9 +1,13 @@
package cn.hutool.core.net;
import cn.hutool.core.codec.PercentCodec;
import cn.hutool.core.util.CharsetUtil;
import org.junit.Assert;
import org.junit.Test;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
public class RFC3986Test {
@Test
@ -26,4 +30,12 @@ public class RFC3986Test {
String encode = RFC3986.QUERY_PARAM_VALUE.encode("a=%25", CharsetUtil.CHARSET_UTF_8, '%');
Assert.assertEquals("a=%25", encode);
}
@Test
public void encodeAllTest() throws UnsupportedEncodingException {
String toVerifyText = "行吧行吧 cargo:1.0,\"Deta-ils:[{";
final String encode = PercentCodec.of(RFC3986.UNRESERVED).setEncodeSpaceAsPlus(true).encode(toVerifyText, CharsetUtil.CHARSET_UTF_8);
final String encodeJdk = URLEncoder.encode(toVerifyText, "UTF-8");
Assert.assertEquals(encode, encodeJdk);
}
}