Skip to content

Commit fdf6430

Browse files
authored
Merge pull request #2115 from MaheshMadushan/Windows_failing_test_fix
PR Fixes failing Test in Windows when attempting to locate files with reserved characters in the file path
2 parents e9b01c6 + 8ce70aa commit fdf6430

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

clickhouse-data/src/main/java/com/clickhouse/data/ClickHouseUtils.java

+11
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,17 @@ public static List<Path> findFiles(String pattern, String... paths) throws IOExc
357357
}
358358

359359
if (!pattern.startsWith("glob:") && !pattern.startsWith("regex:")) {
360+
if (IS_WINDOWS) {
361+
final String reservedCharsWindows = "<>:\"|?*";
362+
pattern.chars().anyMatch(
363+
value -> {
364+
if (value < ' ' || reservedCharsWindows.indexOf(value) != -1) {
365+
throw new IllegalArgumentException("File path contains reserved character <%s>".formatted((char) value));
366+
}
367+
return false;
368+
}
369+
);
370+
}
360371
Path path = Paths.get(pattern);
361372
if (path.isAbsolute()) {
362373
return Collections.singletonList(path);

clickhouse-data/src/test/java/com/clickhouse/data/ClickHouseUtilsTest.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.ArrayList;
88
import java.util.Arrays;
99
import java.util.Collections;
10+
import java.util.Locale;
1011
import java.util.HashMap;
1112
import java.util.LinkedList;
1213
import java.util.List;
@@ -96,8 +97,20 @@ public void testFindFiles() throws IOException {
9697
Assert.assertThrows(IllegalArgumentException.class, () -> ClickHouseUtils.findFiles(null));
9798
Assert.assertThrows(IllegalArgumentException.class, () -> ClickHouseUtils.findFiles(""));
9899

100+
if (System.getProperty("os.name").toLowerCase(Locale.ROOT).contains("windows")) {
101+
Assert.assertThrows(IllegalArgumentException.class, () -> ClickHouseUtils.findFiles("READM?.md"));
102+
Assert.assertThrows(IllegalArgumentException.class, () -> ClickHouseUtils.findFiles("READM<?.md"));
103+
Assert.assertThrows(IllegalArgumentException.class, () -> ClickHouseUtils.findFiles("READM>.md"));
104+
Assert.assertThrows(IllegalArgumentException.class, () -> ClickHouseUtils.findFiles("READM|.md"));
105+
Assert.assertThrows(IllegalArgumentException.class, () -> ClickHouseUtils.findFiles("READM*.md"));
106+
Assert.assertThrows(IllegalArgumentException.class, () -> ClickHouseUtils.findFiles("READM<>:\\\"|?*.md"));
107+
Assert.assertThrows(IllegalArgumentException.class, () -> ClickHouseUtils.findFiles(" "));
108+
}
109+
else {
110+
Assert.assertEquals(ClickHouseUtils.findFiles("READM?.md").size(), 1);
111+
}
112+
99113
Assert.assertEquals(ClickHouseUtils.findFiles("README.md").size(), 1);
100-
Assert.assertEquals(ClickHouseUtils.findFiles("READM?.md").size(), 1);
101114
Assert.assertEquals(ClickHouseUtils.findFiles("glob:*.md").size(), 1);
102115
Assert.assertTrue(ClickHouseUtils.findFiles("glob:**.java", "src", "..").size() >= 1);
103116
Assert.assertTrue(ClickHouseUtils.findFiles("glob:**.java", "src/test").size() >= 1);

0 commit comments

Comments
 (0)