Skip to content

Commit b60fecf

Browse files
committed
Fail on classpath resource names that are blank after removing leading /
Fixes #4752. (cherry picked from commit 7c0f604)
1 parent 6378c88 commit b60fecf

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

documentation/src/docs/asciidoc/release-notes/release-notes-5.13.4.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ repository on GitHub.
2626
[[release-notes-5.13.4-junit-platform-bug-fixes]]
2727
==== Bug Fixes
2828

29-
* ❓
29+
* `ClasspathResourceSelector` no longer allows to be constructed with a resource name that
30+
is blank after removing the leading slash.
3031

3132
[[release-notes-5.13.4-junit-platform-deprecations-and-breaking-changes]]
3233
==== Deprecations and Breaking Changes

junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/ClasspathResourceSelector.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.junit.platform.commons.PreconditionViolationException;
2525
import org.junit.platform.commons.function.Try;
2626
import org.junit.platform.commons.support.Resource;
27+
import org.junit.platform.commons.util.Preconditions;
2728
import org.junit.platform.commons.util.ReflectionUtils;
2829
import org.junit.platform.commons.util.StringUtils;
2930
import org.junit.platform.commons.util.ToStringBuilder;
@@ -61,6 +62,8 @@ public class ClasspathResourceSelector implements DiscoverySelector {
6162
ClasspathResourceSelector(String classpathResourceName, FilePosition position) {
6263
boolean startsWithSlash = classpathResourceName.startsWith("/");
6364
this.classpathResourceName = (startsWithSlash ? classpathResourceName.substring(1) : classpathResourceName);
65+
Preconditions.notBlank(this.classpathResourceName,
66+
"classpath resource name must not be blank after removing leading slash");
6467
this.position = position;
6568
}
6669

platform-tests/src/test/java/org/junit/platform/engine/discovery/DiscoverySelectorsTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,11 @@ void parseDirectorySelectorWithAbsolutePath() {
292292
void selectClasspathResourcesPreconditions() {
293293
assertViolatesPrecondition(() -> selectClasspathResource((String) null));
294294
assertViolatesPrecondition(() -> selectClasspathResource(""));
295+
assertViolatesPrecondition(() -> selectClasspathResource("/"));
295296
assertViolatesPrecondition(() -> selectClasspathResource(" "));
297+
assertViolatesPrecondition(() -> selectClasspathResource("/ "));
296298
assertViolatesPrecondition(() -> selectClasspathResource("\t"));
299+
assertViolatesPrecondition(() -> selectClasspathResource("/\t"));
297300
assertViolatesPrecondition(() -> selectClasspathResource((Set<Resource>) null));
298301
assertViolatesPrecondition(() -> selectClasspathResource(Collections.emptySet()));
299302
assertViolatesPrecondition(() -> selectClasspathResource(Collections.singleton(null)));

0 commit comments

Comments
 (0)