aboutsummaryrefslogtreecommitdiff
path: root/core/src/test/java/fi/iki/elonen/HttpParsingTest.java
blob: 9705c5b03abf238c83bea2fa6112cd43a571ca55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package fi.iki.elonen;

import org.junit.Test;

import java.net.URLDecoder;
import java.net.URLEncoder;

import static junit.framework.Assert.assertEquals;

public class HttpParsingTest extends HttpServerTest {
    @Test
    public void testNormalCharacters() throws Exception {
        for (int i = 0x20; i < 0x80; i++) {
            String hex = Integer.toHexString(i);
            String input = "%" + hex;
            char expected = (char) i;
            assertEquals("" + expected, testServer.decodePercent(input));
        }
    }

    @Test
    public void testMultibyteCharacterSupport() throws Exception {
        String expected = "Chinese \u738b Letters";
        String input = "Chinese+%e7%8e%8b+Letters";
        assertEquals(expected, testServer.decodePercent(input));
    }

    @Test
    public void testPlusInQueryParams() throws Exception {
        assertEquals("foo bar", testServer.decodePercent("foo+bar"));
    }
}