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 @@ -145,6 +145,10 @@ private boolean match(
}

private boolean matches(int index, String input) {
// TODO: Check if this can be done better or prevented earlier.
if (input == null) {
input = "";
}
// return matches(parts[index], input);
if (partsRegex[index] == null) {
String regex = parts[index]
Expand All @@ -157,10 +161,6 @@ private boolean matches(int index, String input) {
.replace("(", "\\(")
.replace(")", "\\)");

// TODO: Check if this can be done better or prevented earlier.
if (input == null) {
input = "";
}
partsRegex[index] = java.util.regex.Pattern.compile(regex);
}
return partsRegex[index].matcher(input).matches();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ class BannedDependenciesTest {
@InjectMocks
private BannedDependencies rule;

@Test
void excludesDoNotUseTransitiveDependenciesNullSafe() throws Exception {
when(session.getCurrentProject()).thenReturn(project);
when(project.getDependencyArtifacts()).thenReturn(ARTIFACT_STUB_FACTORY.getTypedArtifacts());

rule.setSearchTransitive(false);
rule.setExcludes(Collections.singletonList("g:b:*:*:compile:*"));

assertThatCode(rule::execute)
.isInstanceOf(EnforcerRuleException.class)
.hasMessageContaining("g:b:jar:1.0 <--- banned via the exclude/include list");
}

@Test
void excludesDoNotUseTransitiveDependencies() throws Exception {
when(session.getCurrentProject()).thenReturn(project);
Expand Down