@Test
public void escapeURLStrict() throws Exception {

    String unreserved = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.!~*'()";
    assertSame(unreserved, StringEscapeUtil.escapeURL(unreserved));
    // 测试所有ISO-8859-1字符
    StringBuilder buffer = new StringBuilder(256);
    StringBuilder expectedBuffer = new StringBuilder(256 * 3);
    for (int i = 0; i < 256; i++) {
        buffer.append((char) i);
        if (i == ' ') {
            expectedBuffer.append('+');
        } else if (unreserved.indexOf(i) == -1) {
            new Formatter(expectedBuffer).format("%%%02X", i);
        } else {
            expectedBuffer.append((char) i);
        }
    }
    String str = buffer.toString();
    String expectedStr = expectedBuffer.toString();
    assertEquals(expectedStr, StringEscapeUtil.escapeURL(str, "8859_1"));
    // 测试writer
    StringWriter writer = new StringWriter();
    StringEscapeUtil.escapeURL(str, "8859_1", writer);
    assertEquals(expectedStr, writer.toString());
    // 测试中文
    assertEquals("%D6%D0%BB%AA%C8%CB%C3%F1%B9%B2%BA%CD%B9%FA", StringEscapeUtil.escapeURL("中华人民共和国", "GBK"));
    // 中文writer
    writer = new StringWriter();
    StringEscapeUtil.escapeURL("中华人民共和国", "GBK", writer);
    assertEquals("%D6%D0%BB%AA%C8%CB%C3%F1%B9%B2%BA%CD%B9%FA", writer.toString());
}