mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 15:37:46 +00:00
AK+Userland: Make AK::decode_base64 return ErrorOr
This commit is contained in:
parent
f590cd1850
commit
c388a879d7
11 changed files with 31 additions and 43 deletions
|
@ -340,7 +340,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::atob)
|
|||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::BadArgCountOne, "atob");
|
||||
auto string = TRY(vm.argument(0).to_string(global_object));
|
||||
auto decoded = decode_base64(StringView(string));
|
||||
if (!decoded.has_value())
|
||||
if (decoded.is_error())
|
||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::InvalidFormat, "Base64");
|
||||
|
||||
// decode_base64() returns a byte string. LibJS uses UTF-8 for strings. Use Latin1Decoder to convert bytes 128-255 to UTF-8.
|
||||
|
|
|
@ -162,8 +162,8 @@ void ResourceLoader::load(LoadRequest& request, Function<void(ReadonlyBytes, con
|
|||
ByteBuffer data;
|
||||
if (url.data_payload_is_base64()) {
|
||||
auto data_maybe = decode_base64(url.data_payload());
|
||||
if (!data_maybe.has_value()) {
|
||||
auto error_message = "Base64 data contains an invalid character"sv;
|
||||
if (data_maybe.is_error()) {
|
||||
auto error_message = data_maybe.error().string_literal();
|
||||
log_failure(request, error_message);
|
||||
error_callback(error_message, {});
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue