Skip to content

Commit 914769f

Browse files
authored
Do not allow empty env vars (#5983)
Fixes #5026 Signed-off-by: Priyambada Roul <[email protected]>
1 parent 09c42a4 commit 914769f

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,10 @@ private String getConfigurable(
230230
}
231231

232232
if (environment.containsKey(envVarName)) {
233-
return environment.get(envVarName);
233+
String value = environment.get(envVarName);
234+
if (!value.isEmpty()) {
235+
return value;
236+
}
234237
}
235238

236239
for (final Properties properties : propertiesSources) {

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ public void shouldReadDockerSettingsFromUserProperties() {
126126
.isEqualTo("some value");
127127
}
128128

129+
@Test
130+
public void shouldNotReadSettingIfCorrespondingEnvironmentVarIsEmptyString() {
131+
environment.put("DOCKER_FOO", "");
132+
assertThat(newConfig().getEnvVarOrUserProperty("docker.foo", "default"))
133+
.as("reads unprefixed env vars for docker. settings")
134+
.isEqualTo("default");
135+
}
136+
129137
@Test
130138
public void shouldNotReadDockerClientStrategyFromClasspathProperties() {
131139
String currentValue = newConfig().getDockerClientStrategyClassName();

0 commit comments

Comments
 (0)