Skip to content

Commit

Permalink
fix: return exception
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Lemire committed Apr 10, 2024
1 parent f0eb93f commit 6900b0d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
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

0 comments on commit 6900b0d

Please sign in to comment.