Skip to content

Commit

Permalink
Create normalizedHeaders as object with Object prototype. (#12054)
Browse files Browse the repository at this point in the history
Co-authored-by: phryneas <[email protected]>
  • Loading branch information
phryneas and phryneas authored Sep 5, 2024
1 parent aee0f4f commit 35cf186
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/polite-toys-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@apollo/client": patch
---

Fixed a bug where incorrect object access in some Safari extensions could cause a crash.
4 changes: 2 additions & 2 deletions .size-limits.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"dist/apollo-client.min.cjs": 40252,
"import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 33066
"dist/apollo-client.min.cjs": 40251,
"import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 33061
}
7 changes: 4 additions & 3 deletions src/link/http/selectHttpOptionsAndBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ function removeDuplicateHeaders(
): typeof headers {
// If we're not preserving the case, just remove duplicates w/ normalization.
if (!preserveHeaderCase) {
const normalizedHeaders = Object.create(null);
const normalizedHeaders: Record<string, string> = {};
Object.keys(Object(headers)).forEach((name) => {
normalizedHeaders[name.toLowerCase()] = headers[name];
});
Expand All @@ -216,15 +216,16 @@ function removeDuplicateHeaders(
// preserving the original name.
// This allows for non-http-spec-compliant servers that expect intentionally
// capitalized header names (See #6741).
const headerData = Object.create(null);
const headerData: Record<string, { originalName: string; value: string }> =
{};
Object.keys(Object(headers)).forEach((name) => {
headerData[name.toLowerCase()] = {
originalName: name,
value: headers[name],
};
});

const normalizedHeaders = Object.create(null);
const normalizedHeaders: Record<string, string> = {};
Object.keys(headerData).forEach((name) => {
normalizedHeaders[headerData[name].originalName] = headerData[name].value;
});
Expand Down

0 comments on commit 35cf186

Please sign in to comment.