This is an automated email from the ASF dual-hosted git repository.
fanningpj pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/poi.git
The following commit(s) were added to refs/heads/trunk by this push:
new ae232b73d7 windows test issue
ae232b73d7 is described below
commit ae232b73d74daa75806fae1d351ae019959bdc20
Author: PJ Fanning <[email protected]>
AuthorDate: Sun Aug 3 13:54:30 2025 +0100
windows test issue
---
poi/src/test/java/org/apache/poi/util/TestIOUtils.java | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/poi/src/test/java/org/apache/poi/util/TestIOUtils.java
b/poi/src/test/java/org/apache/poi/util/TestIOUtils.java
index 094e138eef..b2e3c673a7 100644
--- a/poi/src/test/java/org/apache/poi/util/TestIOUtils.java
+++ b/poi/src/test/java/org/apache/poi/util/TestIOUtils.java
@@ -594,7 +594,7 @@ final class TestIOUtils {
final File parent =
TempFile.createTempDirectory("path-traversal-test");
try {
// this path is ok because it doesn't walk out of the parent
directory
- final String path0 = "a/b/c/../d/e/../../f/g/./h";
+ final String path0 =
windowsPathIfNecessary("a/b/c/../d/e/../../f/g/./h");
File outFile = IOUtils.newFile(parent, path0);
assertTrue(outFile.getAbsolutePath().endsWith(path0),
"unexpected path: " + outFile.getAbsolutePath());
@@ -609,7 +609,7 @@ final class TestIOUtils {
try {
// this path is ok because it doesn't walk out of the parent
directory
// the initial slash is ignored and the generated path is relative
to the parent directory
- final String path0 = "/a/b/c.txt";
+ final String path0 = windowsPathIfNecessary("/a/b/c.txt");
File outFile = IOUtils.newFile(parent, path0);
assertTrue(outFile.getAbsolutePath().endsWith(path0),
"unexpected path: " + outFile.getAbsolutePath());
@@ -622,13 +622,18 @@ final class TestIOUtils {
void testDisallowedPathTraversal() throws IOException {
final File parent =
TempFile.createTempDirectory("path-traversal-test");
try {
- final String path0 = "../a/b/c.txt";
+ final String path0 = windowsPathIfNecessary("../a/b/c.txt");
Assertions.assertThrows(IOException.class, () ->
IOUtils.newFile(parent, path0));
} finally {
assertTrue(parent.delete());
}
}
+ private static String windowsPathIfNecessary(String path) {
+ // this is a workaround for the Windows file system which doesn't
allow slashes in file names
+ return File.pathSeparatorChar == '/' ? path : path.replace('/',
File.pathSeparatorChar);
+ }
+
/**
* This returns 0 for the first call to skip and then reads
* as requested. This tests that the fallback to read() works.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]