@Test
public void escapeURLLoose() throws Exception {

    String reserved = ";/?:@&=+$,";
    assertEquals("%3B%2F%3F%3A%40%26%3D%2B%24%2C", StringEscapeUtil.escapeURL(reserved, "8859_1", false));
    // 测试所有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 (reserved.indexOf(i) == -1 && i > 32) {
            expectedBuffer.append((char) i);
        } else {
            new Formatter(expectedBuffer).format("%%%02X", i);
        }
    }
    String str = buffer.toString();
    String expectedStr = expectedBuffer.toString();
    assertEquals(expectedStr, StringEscapeUtil.escapeURL(str, "8859_1", false));
    // 测试writer
    StringWriter writer = new StringWriter();
    StringEscapeUtil.escapeURL(str, "8859_1", writer, false);
    assertEquals(expectedStr, writer.toString());
    // 测试中文和全角空格
    str = "中华人民共和国";
    assertSame(str, StringEscapeUtil.escapeURL(str, "GBK", false));
    str = "中华人民共和国\u3000";
    assertEquals("中华人民共和国%A1%A1", StringEscapeUtil.escapeURL(str, "GBK", false));
    // 中文writer
    writer = new StringWriter();
    StringEscapeUtil.escapeURL("中华人民共和国", "GBK", writer, false);
    assertEquals("中华人民共和国", writer.toString());
}