Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Properly decode jar URLs with spaces (%20). Closes #866
- Loading branch information
1 parent
1e9d1d5
commit dc84220
Showing
10 changed files
with
83 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,32 @@ | |||
package cucumber.runtime.io; | |||
|
|||
import cucumber.runtime.CucumberException; | |||
|
|||
import java.io.UnsupportedEncodingException; | |||
import java.net.MalformedURLException; | |||
import java.net.URISyntaxException; | |||
import java.net.URL; | |||
|
|||
public class Helpers { | |||
static boolean hasSuffix(String suffix, String name) { | |||
return suffix == null || name.endsWith(suffix); | |||
} | |||
|
|||
static String filePath(URL url) { | |||
try { | |||
return url.toURI().getSchemeSpecificPart(); | |||
} catch (URISyntaxException e) { | |||
throw new CucumberException(e); | |||
} | |||
} | |||
|
|||
static String jarFilePath(URL jarUrl) throws UnsupportedEncodingException, MalformedURLException { | |||
String urlFile = jarUrl.getFile(); | |||
|
|||
int separatorIndex = urlFile.indexOf("!/"); | |||
if (separatorIndex == -1) { | |||
throw new CucumberException("Not a jar URL: " + jarUrl.toExternalForm()); | |||
} | |||
return filePath(new URL(urlFile.substring(0, separatorIndex))); | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 0 additions & 39 deletions
39
core/src/test/java/cucumber/runtime/io/ClasspathResourceIterableTest.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,40 @@ | |||
package cucumber.runtime.io; | |||
|
|||
import org.junit.Test; | |||
|
|||
import java.io.File; | |||
import java.io.IOException; | |||
import java.io.UnsupportedEncodingException; | |||
import java.net.MalformedURLException; | |||
import java.net.URL; | |||
import java.net.URLConnection; | |||
import java.net.URLStreamHandler; | |||
|
|||
import static cucumber.runtime.io.Helpers.filePath; | |||
import static cucumber.runtime.io.Helpers.jarFilePath; | |||
import static org.junit.Assert.assertEquals; | |||
|
|||
public class HelpersTest { | |||
private static final URLStreamHandler NULL_URL_STREAM_HANDLER = new URLStreamHandler() { | |||
@Override | |||
protected URLConnection openConnection(URL u) throws IOException { | |||
throw new UnsupportedOperationException(); | |||
} | |||
}; | |||
|
|||
@Test | |||
public void computes_file_path_for_file_url() throws UnsupportedEncodingException, MalformedURLException { | |||
URL url = new URL("file:/Users/First%20Last/.m2/repository/info/cukes/cucumber-java/1.2.2/cucumber-java-1.2.2.jar"); | |||
assertEquals(new File("/Users/First Last/.m2/repository/info/cukes/cucumber-java/1.2.2/cucumber-java-1.2.2.jar").getAbsolutePath(), filePath(url)); | |||
} | |||
|
|||
@Test | |||
public void computes_file_path_for_jar_protocols() throws Exception { | |||
assertEquals("foo bar+zap/cucumber-core.jar", jarFilePath(new URL("jar:file:foo%20bar+zap/cucumber-core.jar!/cucumber/runtime/io"))); | |||
assertEquals("foo bar+zap/cucumber-core.jar", jarFilePath(new URL(null, "zip:file:foo%20bar+zap/cucumber-core.jar!/cucumber/runtime/io", NULL_URL_STREAM_HANDLER))); | |||
assertEquals("foo bar+zap/cucumber-core.jar", jarFilePath(new URL(null, "wsjar:file:foo%20bar+zap/cucumber-core.jar!/cucumber/runtime/io", NULL_URL_STREAM_HANDLER))); | |||
assertEquals("foo bar+zap/cucumber-core.jar", jarFilePath(new URL("jar:file:foo%20bar+zap/cucumber-core.jar!/"))); | |||
assertEquals("foo bar+zap/cucumber-core.jar", jarFilePath(new URL(null, "zip:file:foo%20bar+zap/cucumber-core.jar!/", NULL_URL_STREAM_HANDLER))); | |||
assertEquals("foo bar+zap/cucumber-core.jar", jarFilePath(new URL(null, "wsjar:file:foo%20bar+zap/cucumber-core.jar!/", NULL_URL_STREAM_HANDLER))); | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters