Skip to content

Commit

Permalink
Fix merging of multiple headers in pwnedPassword/pwnedPasswordRange (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
wKovacs64 committed Apr 28, 2024
1 parent 5fb6ceb commit aa90167
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/hip-donkeys-mix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'hibp': patch
---

Fix a bug in `pwnedPassword` and `pwnedPasswordRange` modules where the `addPadding` and `userAgent` options could not be used simultaneously.
11 changes: 6 additions & 5 deletions src/api/pwnedpasswords/fetch-from-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ export async function fetchFromApi(
mode = 'sha1',
} = options;

const config = Object.assign(
{},
userAgent ? { headers: { 'User-Agent': userAgent } } : {},
addPadding ? { headers: { 'Add-Padding': 'true' } } : {},
);
const config: RequestInit = {
headers: {
...(userAgent ? { 'User-Agent': userAgent } : {}),
...(addPadding ? { 'Add-Padding': 'true' } : {}),
},
};
const url = `${baseUrl.replace(/\/$/g, '')}${endpoint}?mode=${mode}`;
const response = await fetch(url, config);

Expand Down

0 comments on commit aa90167

Please sign in to comment.