Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,19 @@ public void csvSourceFailsWhenTheReadBreaksMidFile() {
@Test
public void csvSourceNamesTheFileItFailedToRead(@TempDir Path directory) throws IOException {
Path file = truncatedGzip(directory);
CSVDataSource source = new CSVDataSource(file.toString(), ",", 1, AllowedPaths.under(directory));
source.open();

UncheckedIOException thrown = assertThrows(UncheckedIOException.class, () -> readAll(source));

// A GZip member cut short ends with an unexpected EOF rather than a clean end of
// data; the message must name the file so the failure can be traced to it.
assertInstanceOf(EOFException.class, thrown.getCause());
assertTrue(thrown.getMessage().contains(file.toString()), thrown.getMessage());
// Closed even though the read failed: the failure leaves the descriptor open, and
// Windows refuses to delete a file some handle still holds, so an unclosed source
// fails @TempDir's cleanup rather than the assertions below.
try (CSVDataSource source = new CSVDataSource(file.toString(), ",", 1, AllowedPaths.under(directory))) {
source.open();

UncheckedIOException thrown = assertThrows(UncheckedIOException.class, () -> readAll(source));

// A GZip member cut short ends with an unexpected EOF rather than a clean end of
// data; the message must name the file so the failure can be traced to it.
assertInstanceOf(EOFException.class, thrown.getCause());
assertTrue(thrown.getMessage().contains(file.toString()), thrown.getMessage());
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ public void acceptsFileNameStartingWithTwoDots(@TempDir Path baseDir) throws IOE

String validated = AllowedPaths.under(baseDir).validate(dotted.toString());

assertEquals(dotted.toRealPath().toString(), validated);
// Compared against the canonicalisation validate() documents -- absolute and
// normalised -- rather than the real path: on Windows the temporary directory is
// handed over in its short 8.3 form (RUNNER~1), which toRealPath() spells out and
// validate() leaves exactly as it was given.
assertEquals(dotted.toAbsolutePath().normalize().toString(), validated);
}

@Test
Expand Down
Loading