Skip to content

fix: Use locale-invariant toLowerCase for header normalization#1930

Open
anishesg wants to merge 1 commit into
openai:mainfrom
proudhare:fix/ph-issue-1928
Open

fix: Use locale-invariant toLowerCase for header normalization#1930
anishesg wants to merge 1 commit into
openai:mainfrom
proudhare:fix/ph-issue-1928

Conversation

@anishesg

@anishesg anishesg commented Jun 8, 2026

Copy link
Copy Markdown

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.ts line 77, where name.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() with name.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

## Changes being requested

Signed-off-by: anish <anishesg@users.noreply.github.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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' }`,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah good point, the test should expect the lowercased version since that's what Headers actually returns when you iterate

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah good point, the test should expect the lowercased version since that's what Headers actually returns when you iterate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: TypeError: Header name must be a valid HTTP token ["openaı-organization"] on Turkish Windows/Locale

1 participant