Skip to content

Commit

Permalink
fix(node-fetch): inspect null header values correctly (#2051)
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan authored Feb 13, 2025
1 parent aa9a8c9 commit 252f68b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/nine-moose-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@whatwg-node/node-fetch': patch
---

Fix crash on null header values during inspect
2 changes: 1 addition & 1 deletion packages/node-fetch/src/Headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export class PonyfillHeaders implements Headers {
if (key === 'set-cookie') {
record['set-cookie'] = this._setCookies;
} else {
record[key] = value.includes(',') ? value.split(',').map(el => el.trim()) : value;
record[key] = value?.includes(',') ? value.split(',').map(el => el.trim()) : value;
}
});
return `Headers ${inspect(record)}`;
Expand Down
5 changes: 5 additions & 0 deletions packages/node-fetch/tests/Headers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,9 @@ describe('Headers', () => {
['set-cookie', 'bar'],
]);
});
it('inspect correctly with null header values', () => {
const headers = new PonyfillHeaders();
headers.set('X-Header', null!);
expect(inspect(headers)).toBe("Headers { 'x-header': null }");
});
});

0 comments on commit 252f68b

Please sign in to comment.