Skip to content

Commit a6b13a3

Browse files
committed
[JUnit Platform] Fix UniqueId resolution
A unique id of any feature element is prefixed by the unique id of the engine. This prefix, and only this prefix should be skipped. Simply finding the first feature segment is not correct. In practice, because we check if the unique id we try to resolve is prefixed by the engine descriptor, everything does work out fine. But this should help against malformed ids.
1 parent 0e99b18 commit a6b13a3

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

cucumber-junit-platform-engine/src/main/java/io/cucumber/junit/platform/engine/FeatureResolver.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,16 +214,20 @@ void resolveUniqueId(UniqueIdSelector uniqueIdSelector) {
214214
Predicate<TestDescriptor> keepTestWithSelectedId = testDescriptor -> uniqueId
215215
.equals(testDescriptor.getUniqueId());
216216

217+
List<UniqueId.Segment> resolvedSegments = engineDescriptor.getUniqueId().getSegments();
218+
217219
uniqueId.getSegments()
218220
.stream()
221+
.skip(resolvedSegments.size())
222+
.findFirst()
219223
.filter(FeatureOrigin::isFeatureSegment)
220224
.map(UniqueId.Segment::getValue)
221225
.map(URI::create)
222-
.flatMap(this::resolveUri)
223-
.forEach(featureDescriptor -> {
226+
.map(this::resolveUri)
227+
.ifPresent(featureDescriptors -> featureDescriptors.forEach(featureDescriptor -> {
224228
featureDescriptor.prune(keepTestWithSelectedId);
225229
engineDescriptor.mergeFeature(featureDescriptor);
226-
});
230+
}));
227231
}
228232

229233
private Stream<FeatureDescriptor> resolveUri(URI uri) {

0 commit comments

Comments
 (0)