From 5e40db5a17468cc66bb10dc76cbd07ab732fa373 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sun, 1 Jun 2025 06:58:47 -0400 Subject: [PATCH] AK: Remove some now-unnecessary workarounds for simdutf base64 usage --- AK/Base64.cpp | 9 ++------- .../Tests/builtins/TypedArray/Uint8Array.fromBase64.js | 2 +- .../TypedArray/Uint8Array.prototype.setFromBase64.js | 2 +- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/AK/Base64.cpp b/AK/Base64.cpp index 0485bd736cb..6d67ef3b358 100644 --- a/AK/Base64.cpp +++ b/AK/Base64.cpp @@ -45,9 +45,7 @@ static ErrorOr decode_base64_into_impl(StringView input, to_simdutf_last_chunk_handling(last_chunk_handling), decode_up_to_bad_character); - if (result.error == simdutf::BASE64_INPUT_REMAINDER && last_chunk_handling == LastChunkHandling::StopBeforePartial) { - result.error = simdutf::SUCCESS; - } else if (result.error != simdutf::SUCCESS && result.error != simdutf::OUTPUT_BUFFER_TOO_SMALL) { + if (result.error != simdutf::SUCCESS && result.error != simdutf::OUTPUT_BUFFER_TOO_SMALL) { output.resize((result.count / 4) * 3); auto error = [&]() { @@ -69,10 +67,7 @@ static ErrorOr decode_base64_into_impl(StringView input, VERIFY(output_length <= output.size()); output.resize(output_length); - if (last_chunk_handling == LastChunkHandling::StopBeforePartial) - return input.length() - (input.length() % 4); - - return result.error == simdutf::SUCCESS ? input.length() : result.count; + return result.count; } static ErrorOr decode_base64_impl(StringView input, LastChunkHandling last_chunk_handling, simdutf::base64_options options) diff --git a/Libraries/LibJS/Tests/builtins/TypedArray/Uint8Array.fromBase64.js b/Libraries/LibJS/Tests/builtins/TypedArray/Uint8Array.fromBase64.js index 8ca3aa1cbae..ee9085b5607 100644 --- a/Libraries/LibJS/Tests/builtins/TypedArray/Uint8Array.fromBase64.js +++ b/Libraries/LibJS/Tests/builtins/TypedArray/Uint8Array.fromBase64.js @@ -40,7 +40,7 @@ describe("errors", () => { test("invalid padding", () => { expect(() => { Uint8Array.fromBase64("Zm9v=", { lastChunkHandling: "strict" }); - }).toThrowWithMessage(SyntaxError, "Invalid trailing data"); + }).toThrowWithMessage(SyntaxError, "Invalid base64 character"); expect(() => { Uint8Array.fromBase64("Zm9vaa=", { lastChunkHandling: "strict" }); diff --git a/Libraries/LibJS/Tests/builtins/TypedArray/Uint8Array.prototype.setFromBase64.js b/Libraries/LibJS/Tests/builtins/TypedArray/Uint8Array.prototype.setFromBase64.js index da5136a4f53..36b5150c56e 100644 --- a/Libraries/LibJS/Tests/builtins/TypedArray/Uint8Array.prototype.setFromBase64.js +++ b/Libraries/LibJS/Tests/builtins/TypedArray/Uint8Array.prototype.setFromBase64.js @@ -79,7 +79,7 @@ describe("errors", () => { test("invalid padding", () => { expect(() => { new Uint8Array(10).setFromBase64("Zm9v=", { lastChunkHandling: "strict" }); - }).toThrowWithMessage(SyntaxError, "Invalid trailing data"); + }).toThrowWithMessage(SyntaxError, "Invalid base64 character"); expect(() => { new Uint8Array(10).setFromBase64("Zm9vaa=", { lastChunkHandling: "strict" });