Skip to content

Commit 3502b7a

Browse files
committed
Fail on classpath resource names that are blank after removing leading /
Fixes #4752.
1 parent d2d9987 commit 3502b7a

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
@@ -25,6 +25,7 @@
2525
import org.junit.platform.commons.PreconditionViolationException;
2626
import org.junit.platform.commons.function.Try;
2727
import org.junit.platform.commons.support.Resource;
28+
import org.junit.platform.commons.util.Preconditions;
2829
import org.junit.platform.commons.util.ReflectionUtils;
2930
import org.junit.platform.commons.util.StringUtils;
3031
import org.junit.platform.commons.util.ToStringBuilder;
@@ -64,6 +65,8 @@ public final class ClasspathResourceSelector implements DiscoverySelector {
6465
ClasspathResourceSelector(String classpathResourceName, @Nullable FilePosition position) {
6566
boolean startsWithSlash = classpathResourceName.startsWith("/");
6667
this.classpathResourceName = (startsWithSlash ? classpathResourceName.substring(1) : classpathResourceName);
68+
Preconditions.notBlank(this.classpathResourceName,
69+
"classpath resource name must not be blank after removing leading slash");
6770
this.position = position;
6871
}
6972

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
@@ -299,8 +299,11 @@ void parseDirectorySelectorWithAbsolutePath() {
299299
void selectClasspathResourcesPreconditions() {
300300
assertViolatesPrecondition(() -> selectClasspathResource((String) null));
301301
assertViolatesPrecondition(() -> selectClasspathResource(""));
302+
assertViolatesPrecondition(() -> selectClasspathResource("/"));
302303
assertViolatesPrecondition(() -> selectClasspathResource(" "));
304+
assertViolatesPrecondition(() -> selectClasspathResource("/ "));
303305
assertViolatesPrecondition(() -> selectClasspathResource("\t"));
306+
assertViolatesPrecondition(() -> selectClasspathResource("/\t"));
304307
assertViolatesPrecondition(() -> selectClasspathResource((Set<Resource>) null));
305308
assertViolatesPrecondition(() -> selectClasspathResource(Collections.emptySet()));
306309
assertViolatesPrecondition(() -> selectClasspathResource(Collections.singleton(null)));

0 commit comments

Comments
 (0)