From baa782a07870c9b1f39f359fe6b240789b130032 Mon Sep 17 00:00:00 2001 From: Timur Rakhmatullin <174210871+TimurRakhmatullin86@users.noreply.github.com> Date: Sun, 5 Jul 2026 19:16:56 -0700 Subject: [PATCH] Use fixed locale when deriving environment variable names from properties MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TestcontainersConfiguration derives the environment variable name for a configuration property by upper-casing the property name with the default locale. Under locales with different case-mapping rules (for example the Turkish locale, where 'i' maps to the dotted capital 'İ'), the derived name no longer matches the ASCII environment variable that is actually set, so the environment variable is silently ignored. Use Locale.ROOT for the case conversion so that resolution of configuration from environment variables is independent of the JVM default locale. --- .../utility/TestcontainersConfiguration.java | 3 ++- .../TestcontainersConfigurationTest.java | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/testcontainers/utility/TestcontainersConfiguration.java b/core/src/main/java/org/testcontainers/utility/TestcontainersConfiguration.java index 5c80b82ba9c..a332daae0f9 100644 --- a/core/src/main/java/org/testcontainers/utility/TestcontainersConfiguration.java +++ b/core/src/main/java/org/testcontainers/utility/TestcontainersConfiguration.java @@ -22,6 +22,7 @@ import java.io.OutputStream; import java.net.MalformedURLException; import java.net.URL; +import java.util.Locale; import java.util.Map; import java.util.Optional; import java.util.Properties; @@ -231,7 +232,7 @@ private String getConfigurable( @Nullable final String defaultValue, Properties... propertiesSources ) { - String envVarName = propertyName.replaceAll("\\.", "_").toUpperCase(); + String envVarName = propertyName.replaceAll("\\.", "_").toUpperCase(Locale.ROOT); if (!envVarName.startsWith("TESTCONTAINERS_") && !envVarName.startsWith("DOCKER_")) { envVarName = "TESTCONTAINERS_" + envVarName; } diff --git a/core/src/test/java/org/testcontainers/utility/TestcontainersConfigurationTest.java b/core/src/test/java/org/testcontainers/utility/TestcontainersConfigurationTest.java index 4e0520af5ba..489b0ffc72c 100644 --- a/core/src/test/java/org/testcontainers/utility/TestcontainersConfigurationTest.java +++ b/core/src/test/java/org/testcontainers/utility/TestcontainersConfigurationTest.java @@ -4,6 +4,7 @@ import org.junit.jupiter.api.Test; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import java.util.Properties; import java.util.UUID; @@ -225,6 +226,24 @@ void shouldTrimImageNames() { .isEqualTo("testcontainers/ryuk:0.3.2"); } + @Test + void shouldReadEnvVarRegardlessOfDefaultLocale() { + // Property names such as "image.substitutor" contain the letter 'i', which + // upper-cases to a dotted capital 'İ' (U+0130) under the Turkish locale. The + // derived environment variable name must not depend on the JVM default locale, + // otherwise the lookup silently fails and the environment variable is ignored. + Locale previousDefault = Locale.getDefault(); + try { + Locale.setDefault(new Locale("tr", "TR")); + environment.put("TESTCONTAINERS_IMAGE_SUBSTITUTOR", "com.example.MySubstitutor"); + assertThat(newConfig().getImageSubstitutorClassName()) + .as("environment variables are resolved independently of the default locale") + .isEqualTo("com.example.MySubstitutor"); + } finally { + Locale.setDefault(previousDefault); + } + } + private TestcontainersConfiguration newConfig() { return new TestcontainersConfiguration(userProperties, classpathProperties, environment); }