This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git
The following commit(s) were added to refs/heads/master by this push:
new c1310d3ef [SUREFIRE-3596] Make report filename filtering platform
independent
c1310d3ef is described below
commit c1310d3ef30117f2605571e9f2642bd500dcbc1b
Author: Alpha <[email protected]>
AuthorDate: Sun Nov 15 07:52:02 2026 +0800
[SUREFIRE-3596] Make report filename filtering platform independent
---
.../plugin/surefire/report/FileReporterUtils.java | 8 ++---
.../FileReporterUtilsPlatformIndependentTest.java | 39 ++++++++++++++++++++++
2 files changed, 42 insertions(+), 5 deletions(-)
diff --git
a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/FileReporterUtils.java
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/FileReporterUtils.java
index 3b693134e..e4baf2a5d 100644
---
a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/FileReporterUtils.java
+++
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/FileReporterUtils.java
@@ -18,8 +18,6 @@
*/
package org.apache.maven.plugin.surefire.report;
-import static org.apache.maven.surefire.shared.lang3.SystemUtils.IS_OS_WINDOWS;
-
/**
* Utils class for file-based reporters.
*
@@ -32,7 +30,7 @@ private FileReporterUtils() {
public static String stripIllegalFilenameChars(String original) {
StringBuilder result = new StringBuilder(original);
- String illegalChars = getOSSpecificIllegalChars();
+ String illegalChars = getIllegalChars();
for (int i = 0, len = result.length(); i < len; i++) {
char charFromOriginal = result.charAt(i);
boolean isIllegalChar = illegalChars.indexOf(charFromOriginal) !=
-1;
@@ -43,11 +41,11 @@ public static String stripIllegalFilenameChars(String
original) {
return result.toString();
}
- private static String getOSSpecificIllegalChars() {
+ private static String getIllegalChars() {
// forbidden and quoted characters
// https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file
// https://cygwin.com/cygwin-ug-net/using-specialnames.html
//
https://www.cyberciti.biz/faq/linuxunix-rules-for-naming-file-and-directory-names/
- return IS_OS_WINDOWS ? "[],\\/:*?\"<>|\0" : "()&\\/:*?\"<>|\0";
+ return "[],()&\\/:*?\"<>|\0";
}
}
diff --git
a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/FileReporterUtilsPlatformIndependentTest.java
b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/FileReporterUtilsPlatformIndependentTest.java
new file mode 100644
index 000000000..d36c2fc96
--- /dev/null
+++
b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/FileReporterUtilsPlatformIndependentTest.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugin.surefire.report;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class FileReporterUtilsPlatformIndependentTest {
+
+ @Test
+ public void stripsCharactersDisallowedOnAnySupportedPlatform() {
+ String disallowedOnSomePlatforms = "[]()&\\/:*?\"<>|\0";
+
+ for (int i = 0; i < disallowedOnSomePlatforms.length(); i++) {
+ char character = disallowedOnSomePlatforms.charAt(i);
+ assertEquals(
+ "_",
+
FileReporterUtils.stripIllegalFilenameChars(String.valueOf(character)),
+ "Character U+" + String.format("%04X", (int) character) +
" should be replaced");
+ }
+ }
+}