Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix: return exception
  • Loading branch information
Daniel Lemire committed Apr 10, 2024
commit 6900b0dce7cf6f9caaa852fa7a4d574cd0462d78
6 changes: 5 additions & 1 deletion lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,11 @@ function btoa(input) {
if (arguments.length === 0) {
throw new ERR_MISSING_ARGS('input');
}
return _btoa(`${input}`);
const result = _btoa(`${input}`);
if (result === -1) {
throw lazyDOMException('Invalid character', 'InvalidCharacterError');
}
return result;
}

function atob(input) {
Expand Down
2 changes: 1 addition & 1 deletion src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,7 @@ static void Btoa(const FunctionCallbackInfo<Value>& args) {
value.length(),
stack_buf.out());
if (out_len == 0) { // error
return args.GetReturnValue().SetEmptyString();
return args.GetReturnValue().Set(-1);
}
size_t expected_length = simdutf::base64_length_from_binary(out_len);
buffer.AllocateSufficientStorage(expected_length + 1);
Expand Down