Skip to content

Commit 988e16a

Browse files
authored
#664 Fixed handling of the paths with + in them (#665)
1 parent bead0b3 commit 988e16a

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
55

66
### Fixed
77
- Retry any exceptions (not just `DockerClientException`) on image pull ([\#662](https://github.com/testcontainers/testcontainers-java/issues/662))
8+
- Fixed handling of the paths with `+` in them ([\#664](https://github.com/testcontainers/testcontainers-java/issues/664))
89

910
### Changed
1011
- Database container images are now pinned to a specific version rather than using `latest`. The tags selected are the most recent as of the time of this change. If a JDBC URL is used with no tag specified, a WARN level log message is output, pending a future change to make tags mandatory in the JDBC URL. ([\#671](https://github.com/testcontainers/testcontainers-java/issues/671))

core/src/main/java/org/testcontainers/utility/MountableFile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ private static URL getClasspathResource(@NotNull final String resourcePath, @Not
148148
private static String unencodeResourceURIToFilePath(@NotNull final String resource) {
149149
try {
150150
// Convert any url-encoded characters (e.g. spaces) back into unencoded form
151-
return URLDecoder.decode(resource, Charsets.UTF_8.name())
151+
return URLDecoder.decode(resource.replaceAll("\\+", "%2B"), Charsets.UTF_8.name())
152152
.replaceFirst("jar:", "")
153153
.replaceFirst("file:", "")
154154
.replaceAll("!.*", "");

core/src/test/java/org/testcontainers/utility/MountableFileTest.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ public void forHostPathWithSpaces() throws Exception {
6565
assertFalse("The resolved path does not contain an escaped space", mountableFile.getResolvedPath().contains("\\ "));
6666
}
6767

68+
@Test
69+
public void forHostPathWithPlus() throws Exception {
70+
final Path file = createTempFile("some+path");
71+
final MountableFile mountableFile = MountableFile.forHostPath(file.toString());
72+
73+
performChecks(mountableFile);
74+
75+
assertTrue("The resolved path contains the original space", mountableFile.getResolvedPath().contains("+"));
76+
assertFalse("The resolved path does not contain an escaped space", mountableFile.getResolvedPath().contains(" "));
77+
}
78+
6879
@Test
6980
public void forClasspathResourceWithPermission() throws Exception {
7081
final MountableFile mountableFile = MountableFile.forClasspathResource("mappable-resource/test-resource.txt",
@@ -113,4 +124,4 @@ private void performChecks(final MountableFile mountableFile) {
113124
assertFalse("The filesystem path '" + mountablePath + "' does not contain any URL escaping", mountablePath.contains("%20"));
114125
}
115126

116-
}
127+
}

0 commit comments

Comments
 (0)