Use fixed locale when deriving environment variable names from properties#11915
Open
TimurRakhmatullin86 wants to merge 1 commit into
Open
Conversation
…ties 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.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe the broken behaviour
TestcontainersConfiguration#getConfigurablemaps a configuration propertyname to the corresponding environment variable name by upper-casing it:
String#toUpperCase()uses the JVM default locale. Several property namescontain the letter
i(docker.client.strategy,image.substitutor,client.ping.timeout,testcontainers.reuse.enable, ...). Under a localewith different case-mapping rules — most notably the Turkish locale, where
iupper-cases to the dotted capitalİ(U+0130) — the derived name becomese.g.
TESTCONTAINERS_İMAGE_SUBSTİTUTORinstead ofTESTCONTAINERS_IMAGE_SUBSTITUTOR. It no longer matches the ASCII environmentvariable that is actually set in the process, so the variable is silently
ignored and Testcontainers falls back to the property/default value.
This reproduces on any JVM whose default locale has non-ASCII case mapping for
i(e.g. started with-Duser.language=tr, or on a machine with a Turkish orAzerbaijani system locale). The failure is silent — no error is logged, the
environment variable simply has no effect — which makes it easy to miss.
How the change fixes it
Derive the environment variable name with
Locale.ROOT, so the caseconversion is independent of the JVM default locale.
The change is intentionally scoped to this single configuration entry point.
Other locale-less
toUpperCase()/toLowerCase()call sites exist elsewhere inthe codebase, but they are left out to keep this fix atomic and easy to review.
Test
Added
TestcontainersConfigurationTest#shouldReadEnvVarRegardlessOfDefaultLocale,which sets the default locale to Turkish and verifies that an environment
variable is still resolved. It fails before the change and passes after it;
the default locale is restored in a
finallyblock.