Skip to content

Commit

Permalink
Issue #4033 - Splitting badDecodePath
Browse files Browse the repository at this point in the history
Signed-off-by: Joakim Erdfelt <[email protected]>
  • Loading branch information
joakime committed Nov 5, 2019
1 parent 7313036 commit 9720fb7
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions jetty-util/src/test/java/org/eclipse/jetty/util/URIUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
Expand Down Expand Up @@ -87,6 +88,24 @@ public static Stream<Arguments> decodePathSource()
arguments.add(Arguments.of("/f%d8%a9%d8%a9%2523;ignore/bar;ignore", "/f\u0629\u0629%23/bar"));
arguments.add(Arguments.of("foo%2523%3b%2c:%3db%20a%20r;rubbish", "foo%23;,:=b a r"));

// Deprecated Microsoft Percent-U encoding
arguments.add(Arguments.of("abc%u3040", "abc\u3040"));

return arguments.stream();
}

@ParameterizedTest(name = "[{index}] {0}")
@MethodSource("decodePathSource")
public void testDecodePath(String encodedPath, String expectedPath)
{
String path = URIUtil.decodePath(encodedPath);
assertEquals(expectedPath, path);
}

public static Stream<Arguments> badDecodePathSource()
{
List<Arguments> arguments = new ArrayList<>();

// Test for null character (real world ugly test case)
byte[] oddBytes = {'/', 0x00, '/'};
String odd = new String(oddBytes, StandardCharsets.ISO_8859_1);
Expand All @@ -95,12 +114,18 @@ public static Stream<Arguments> decodePathSource()
// Deprecated Microsoft Percent-U encoding
arguments.add(Arguments.of("abc%u3040", "abc\u3040"));

// Lenient decode
// Bad %## encoding
arguments.add(Arguments.of("abc%xyz", "abc%xyz")); // not a "%##"

// Incomplete %## encoding
arguments.add(Arguments.of("abc%", "abc%")); // percent at end of string
arguments.add(Arguments.of("abc%A", "abc%A")); // incomplete "%##" at end of string

// Invalid microsoft %u#### encoding
arguments.add(Arguments.of("abc%uvwxyz", "abc%uvwxyz")); // not a valid "%u####"
arguments.add(Arguments.of("abc%uEFGHIJ", "abc%uEFGHIJ")); // not a valid "%u####"

// Incomplete microsoft %u#### encoding
arguments.add(Arguments.of("abc%uABC", "abc%uABC")); // incomplete "%u####"
arguments.add(Arguments.of("abc%uAB", "abc%uAB")); // incomplete "%u####"
arguments.add(Arguments.of("abc%uA", "abc%uA")); // incomplete "%u####"
Expand All @@ -110,11 +135,12 @@ public static Stream<Arguments> decodePathSource()
}

@ParameterizedTest(name = "[{index}] {0}")
@MethodSource("decodePathSource")
public void testDecodePath(String encodedPath, String expectedPath)
@MethodSource("badDecodePathSource")
public void testBadDecodePath(String encodedPath)
{
String path = URIUtil.decodePath(encodedPath);
assertEquals(expectedPath, path);
// TODO: what exception type should these throw?
assertThrows(IllegalArgumentException.class, () -> URIUtil.decodePath(encodedPath));
// NOTE: the decodePath() will attempt UTF-8 then fallback to ISO8859-1
}

@Test
Expand Down

0 comments on commit 9720fb7

Please sign in to comment.