Skip to content
Open
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 @@ -513,12 +513,13 @@ public boolean isCaseSensitive() {

/**
* Retrieves the root extracted from the name.
* Matching respects the case sensitivity of this file system.
* @param name the name to extract the root from
* @return an optional containing the root or empty.
*/
public Optional<String> rootFor(final String name) {
for (String sysRoot : data.roots) {
if (name.startsWith(sysRoot)) {
if (name.regionMatches(!isCaseSensitive(), 0, sysRoot, 0, sysRoot.length())) {
return Optional.of(sysRoot);
}
}
Expand Down Expand Up @@ -773,7 +774,7 @@ public Builder setName(final String name) {
Pair<String, String> splitRoot(final String name) {
String workingName = name;
String workingRoot = fsInfo.rootFor(name).orElse("");
if (!workingRoot.isEmpty() && workingName.startsWith(workingRoot)) {
if (!workingRoot.isEmpty()) {
workingName = workingName.substring(workingRoot.length());
}
return ImmutablePair.of(workingRoot, workingName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.FieldSource;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
Expand All @@ -50,6 +51,17 @@
public class DocumentNameTest {
private static final FSInfo[] TEST_SUITE = FSInfoTest.TEST_SUITE;

@ParameterizedTest
@ValueSource(booleans = {true, false})
void splitRootRespectsCaseSensitivity(boolean caseSensitive) {
FSInfo info = new FSInfo("test", "\\", caseSensitive, List.of("F:\\"));
String path = "f:\\workspace\\target\\rat.txt";
var result = DocumentName.builder(info).splitRoot(path);

assertThat(result.getLeft()).isEqualTo(caseSensitive ? "" : "F:\\");
assertThat(result.getRight()).isEqualTo(caseSensitive ? path : "workspace\\target\\rat.txt");
}

/**
* Create a list of mocked files from the specified directory.
* @param directory the native directory to read.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.TreeMap;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.FieldSource;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
Expand All @@ -59,6 +61,20 @@ public class FSInfoTest {

public static final DocumentName.FSInfo[] TEST_SUITE = {UNIX, WINDOWS, OSX};

@ParameterizedTest
@ValueSource(booleans = {true, false})
void rootForRespectsCaseSensitivity(boolean caseSensitive) {
DocumentName.FSInfo info = new DocumentName.FSInfo("test", "\\", caseSensitive, List.of("C:\\", "F:\\"));

assertThat(info.rootFor("F:\\workspace\\target\\rat.txt")).contains("F:\\");
assertThat(info.rootFor("f:\\workspace\\target\\rat.txt"))
.isEqualTo(caseSensitive ? Optional.empty() : Optional.of("F:\\"));
assertThat(info.rootFor("c:\\workspace\\target\\rat.txt"))
.isEqualTo(caseSensitive ? Optional.empty() : Optional.of("C:\\"));
assertThat(info.rootFor("G:\\workspace\\target\\rat.txt")).isEmpty();
assertThat(info.rootFor("target\\rat.txt")).isEmpty();
}

@ParameterizedTest
@FieldSource("TEST_SUITE")
void normalizeTest(DocumentName.FSInfo info) {
Expand Down
3 changes: 3 additions & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ in order to be properly linked in site reports.
</release>
-->
<release version="1.0.0-SNAPSHOT" date="xxxx-yy-zz" description="Current SNAPSHOT - release to be done">
<action issue="RAT-585" type="fix" dev="pottlinger" due-to="Konrad Windszus">
Respect filesystem case sensitivity when matching path roots, preventing lowercase Windows drive letters from being treated as relative report paths.
</action>
<action issue="RAT-569" type="fix" dev="pottlinger" due-to="Arturo Bernal">
Fix applying configured exclusion rules to resources added via Ant ResourceCollections, including nested filesets and externally resolved collections such as Gradle fileTree elements.
</action>
Expand Down
Loading