Skip to content

Commit

Permalink
fix(ponyfill/btoa): handle incoming value as binary encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Aug 22, 2022
1 parent 3e29a63 commit 982fa96
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/orange-wombats-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@whatwg-node/fetch': patch
---

fix(ponyfill/btoa): handle incoming value as binary encoding
2 changes: 1 addition & 1 deletion packages/fetch/dist/create-node-ponyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ module.exports = function createNodePonyfill(opts = {}) {
ponyfills.btoa = globalThis.btoa
if (!ponyfills.btoa) {
ponyfills.btoa = function btoa(data) {
return Buffer.from(data).toString('base64');
return Buffer.from(data, 'binary').toString('base64');
};
}

Expand Down
4 changes: 2 additions & 2 deletions packages/fetch/tests/btoa.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { btoa } from '@whatwg-node/fetch';
it('should work as expected', () => {
expect(btoa('Hello, world!')).toBe('SGVsbG8sIHdvcmxkIQ==');
})
expect(btoa('Hello, world!')).toBe('SGVsbG8sIHdvcmxkIQ==');
});

0 comments on commit 982fa96

Please sign in to comment.