Repository navigation
Conversation
TreeMap with String.CASE_INSENSITIVE_ORDER is not safe under locales like Turkish where I/i case conversion is not ASCII. HTTP header names must compare with Locale.ROOT rules so keys such as OpenAI-Organization resolve reliably. Fixes openai#755
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 104ffc3a52
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| fun caseInsensitiveUnderTurkishLocale() { | ||
| val previous = Locale.getDefault() | ||
| try { | ||
| Locale.setDefault(Locale("tr", "TR")) |
There was a problem hiding this comment.
Isolate the locale-changing test from parallel tests
Under this repo's openai.kotlin test configuration, JUnit runs tests concurrently (buildSrc/src/main/kotlin/openai.kotlin.gradle.kts lines 33-35), but this changes the JVM-wide default locale while unrelated tests may still be executing. @ResourceLock(Resources.LOCALE) only serializes tests that also take that lock, so concurrent tests that construct ClientOptions/OpenAIOkHttpClient can call LogLevel.fromEnv() under Turkish locale; when OPENAI_LOG is set to values like INFO, default-locale lowercasing turns it into ınfo and the SDK silently uses OFF. Please make this test truly isolated from the rest of the parallel suite, or avoid mutating the process default locale.
Useful? React with 👍 / 👎.
|
Closing after re-verification: this PR does not fix a real defect in Under a Turkish default locale (
OpenJDK implements that comparator with Unicode The unit test added here would also pass on Sorry for the noise — the Node SDK locale issue is a different API surface. Leaving #755 for maintainers to close or re-scope if they want defensive hardening anyway. |
|
Closing as non-fix: CASE_INSENSITIVE_ORDER is already locale-independent (verified under tr_TR). |
Summary
Fixes #755.
Under locales such as Turkish (
tr_TR), case conversion ofI/iis not ASCII (I→ı,i→İ).HeadersusedTreeMap(String.CASE_INSENSITIVE_ORDER)for case-insensitive header names; this change pins comparison toLocale.ROOTso HTTP header names (e.g.OpenAI-Organization,OpenAI-Project) resolve consistently regardless of the JVM default locale.This is the Java equivalent of the Node SDK Turkish-locale header normalization fix (openai/openai-node#1928 / #1941).
Change
In
Headers.kt, both the builder map and the built immutable map now use:instead of
String.CASE_INSENSITIVE_ORDER.Test plan
caseInsensitiveUnderTurkishLocalethat setsLocale("tr", "TR"), putsOpenAI-Organization/OpenAI-Project, asserts case-insensitive get for mixed/upper/lower ASCII keys, restores locale infinally, and uses@ResourceLock(Resources.LOCALE)for parallel tests../gradlew :openai-java-core:test --tests "com.openai.core.http.HeadersTest"→ BUILD SUCCESSFULNotes
Hand-written core path only (
Headers.kt+ test). No generated API model changes.AI-assisted implementation; human-reviewed before open.