Skip to content

Commit

Permalink
#664 Fixed handling of the paths with + in them
Browse files Browse the repository at this point in the history
  • Loading branch information
bsideup committed Apr 26, 2018
1 parent d07356c commit b625e62
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file.
## UNRELEASED

### Fixed
- Fixed handling of the paths with `+` in them ([\#664](https://github.com/testcontainers/testcontainers-java/issues/664))

### Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ private static URL getClasspathResource(@NotNull final String resourcePath, @Not
private static String unencodeResourceURIToFilePath(@NotNull final String resource) {
try {
// Convert any url-encoded characters (e.g. spaces) back into unencoded form
return URLDecoder.decode(resource, Charsets.UTF_8.name())
return URLDecoder.decode(resource.replaceAll("\\+", "%2B"), Charsets.UTF_8.name())
.replaceFirst("jar:", "")
.replaceFirst("file:", "")
.replaceAll("!.*", "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ public void forHostPathWithSpaces() throws Exception {
assertFalse("The resolved path does not contain an escaped space", mountableFile.getResolvedPath().contains("\\ "));
}

@Test
public void forHostPathWithPlus() throws Exception {
final Path file = createTempFile("some+path");
final MountableFile mountableFile = MountableFile.forHostPath(file.toString());

performChecks(mountableFile);

assertTrue("The resolved path contains the original space", mountableFile.getResolvedPath().contains("+"));
assertFalse("The resolved path does not contain an escaped space", mountableFile.getResolvedPath().contains(" "));
}

@Test
public void forClasspathResourceWithPermission() throws Exception {
final MountableFile mountableFile = MountableFile.forClasspathResource("mappable-resource/test-resource.txt",
Expand Down Expand Up @@ -113,4 +124,4 @@ private void performChecks(final MountableFile mountableFile) {
assertFalse("The filesystem path '" + mountablePath + "' does not contain any URL escaping", mountablePath.contains("%20"));
}

}
}

0 comments on commit b625e62

Please sign in to comment.