fix: Use locale-invariant toLowerCase for header normalization#1930
fix: Use locale-invariant toLowerCase for header normalization#1930anishesg wants to merge 1 commit into
Conversation
## Changes being requested Signed-off-by: anish <anishesg@users.noreply.github.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4902cbd4e7
ℹ️ 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".
| 'OpenAI-Organization': 'org-123', | ||
| }, | ||
| ], | ||
| `NullableHeaders { 'OpenAI-Organization': 'org-123' }`, |
There was a problem hiding this comment.
Expect normalized header names in the new test
This expected value does not match what buildHeaders returns for object inputs: it ultimately stores the entry in a WHATWG Headers, and Headers.append('OpenAI-Organization', ...) normalizes the name to openai-organization on iteration. As written, this new case fails on the standard Node Headers implementation even though the product code lowercases the header name correctly.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
ah good point, the test should expect the lowercased version since that's what Headers actually returns when you iterate
There was a problem hiding this comment.
ah good point, the test should expect the lowercased version since that's what Headers actually returns when you iterate
Changes being requested
This PR fixes a critical bug where the SDK crashes on systems running with Turkish locale (tr-TR) on Windows. The root cause is in
src/internal/headers.tsline 77, wherename.toLowerCase()performs locale-sensitive string conversion. On Turkish locales, uppercase 'I' converts to dotless 'ı' instead of 'i', producing invalid HTTP header names like 'openaı-organization' that violate HTTP token validation in Node.js's underlying network layer (undici).The fix replaces
name.toLowerCase()withname.toLocaleLowerCase('en-US')to ensure locale-invariant header normalization that always produces ASCII-compliant header names regardless of system locale. This is a minimal one-line change that aligns with HTTP specification requirements.I've also added test cases that verify header names containing 'I' (like 'OpenAI-Organization') are normalized correctly and that case-insensitive header merging works as expected.
Additional context & links
This issue affects Turkish Windows users and potentially users of other locales with non-standard case mappings. The Turkish 'I' problem is a well-known locale-sensitivity issue in JavaScript string operations.
Fixes #1928