Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature files with space in filename generate Illegal Character Exception (Junit5 Platform) #2520

Closed
lgringo opened this issue Apr 11, 2022 · 1 comment · Fixed by #2521
Closed

Comments

@lgringo
Copy link
Contributor

lgringo commented Apr 11, 2022

👓 What did you see?

When running test suite, if a name of a feature file contains a space character, program exits with :

Internal Error occurred.
org.junit.platform.commons.JUnitException: TestEngine with ID 'cucumber' failed to discover tests
	at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discoverEngineRoot(EngineDiscoveryOrchestrator.java:160)
	at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discoverSafely(EngineDiscoveryOrchestrator.java:134)
	at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discover(EngineDiscoveryOrchestrator.java:108)
	at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discover(EngineDiscoveryOrchestrator.java:80)
	at org.junit.platform.launcher.core.DefaultLauncher.discover(DefaultLauncher.java:110)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
	at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
	at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:53)
	at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:71)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
	at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
Caused by: java.lang.IllegalArgumentException: Illegal character in path at index 49: classpath:/io/cucumber/junit/platform/engine/with space.feature
	at java.base/java.net.URI.create(URI.java:883)
	at io.cucumber.junit.platform.engine.FeatureOrigin.fromUri(FeatureOrigin.java:34)
	at io.cucumber.junit.platform.engine.FeatureResolver.createFeatureDescriptor(FeatureResolver.java:78)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
	at java.base/java.util.stream.SortedOps$SizedRefSortingSink.end(SortedOps.java:357)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
	at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497)
	at io.cucumber.junit.platform.engine.FeatureResolver.resolveClasspathRoot(FeatureResolver.java:197)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
	at io.cucumber.junit.platform.engine.DiscoverySelectorResolver.resolve(DiscoverySelectorResolver.java:74)
	at io.cucumber.junit.platform.engine.DiscoverySelectorResolver.resolveSelectors(DiscoverySelectorResolver.java:47)
	at io.cucumber.junit.platform.engine.CucumberTestEngine.discover(CucumberTestEngine.java:43)
	at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discoverEngineRoot(EngineDiscoveryOrchestrator.java:152)
	... 13 more
Caused by: java.net.URISyntaxException: Illegal character in path at index 49: classpath:/io/cucumber/junit/platform/engine/with space.feature
	at java.base/java.net.URI$Parser.fail(URI.java:2913)
	at java.base/java.net.URI$Parser.checkChars(URI.java:3084)
	at java.base/java.net.URI$Parser.parseHierarchical(URI.java:3166)
	at java.base/java.net.URI$Parser.parse(URI.java:3114)
	at java.base/java.net.URI.<init>(URI.java:600)
	at java.base/java.net.URI.create(URI.java:881)
	... 29 more

✅ What did you expect to see?

Tests execution

📦 Which tool/library version are you using?

  • JDK: 11 & 17
  • Cucumber : 7.2.3 & 7.3.0-SNAPSHOT
  • Junit: 5.8.2
  • OS: Linux (Ubuntu)

🔬 How could we reproduce it?

Steps to reproduce the behavior:

  1. Clone this repo
  2. Create a file called 'with space.feature' into `junit-platform-engine/src/test/resources/io/cucumber/junit/platform/engine'
  3. Run tests
  4. See error
@lgringo
Copy link
Contributor Author

lgringo commented Apr 11, 2022

The problem comes from FeatureOrigin.fromri(URI uri) method. A slash is added because

                // ClasspathResourceSource.from expects all resources to start
                // with a forward slash

But this method uses URI.create and uri.getSchemeSpecificPart().

Javadoc of URI.create (extract) :

This method is provided for use in situations where it is known that the given string is a legal URI

Javadoc of URI.getSchemeSpecificPart (extract):

Returns the decoded scheme-specific part of this URI.

So URI.create waits for legal (encoded) URI, but getSchemeSpecificPart decodes the URI.

URI.getRawSchemeSpecificPart can be use instead, to not devode URI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant