diff --git a/Userland/Libraries/LibJS/Runtime/Uint8Array.cpp b/Userland/Libraries/LibJS/Runtime/Uint8Array.cpp index b6b3ed4df82..d28744c02c4 100644 --- a/Userland/Libraries/LibJS/Runtime/Uint8Array.cpp +++ b/Userland/Libraries/LibJS/Runtime/Uint8Array.cpp @@ -729,7 +729,7 @@ DecodeResult from_base64(VM& vm, StringView string, Alphabet alphabet, LastChunk ch = '+'; } // iii. Else if char is "_", then - else if (ch == '-') { + else if (ch == '_') { // 1. Set char to "/". ch = '/'; } diff --git a/Userland/Libraries/LibJS/Tests/builtins/TypedArray/Uint8Array.fromBase64.js b/Userland/Libraries/LibJS/Tests/builtins/TypedArray/Uint8Array.fromBase64.js index 154fc09f7ba..b7df4acf0eb 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/TypedArray/Uint8Array.fromBase64.js +++ b/Userland/Libraries/LibJS/Tests/builtins/TypedArray/Uint8Array.fromBase64.js @@ -108,6 +108,25 @@ describe("correct behavior", () => { decodeEqual("8J-kkw==", "🤓", options); decodeEqual("8J-kk2Zvb_CflpY=", "🤓foo🖖", options); + + decodeEqual("b2g_", "oh?", options); + }); + + test("strict mode with base64url alphabet", () => { + const options = { alphabet: "base64url", lastChunkHandling: "strict" }; + + decodeEqual("", "", options); + decodeEqual("Zg==", "f", options); + decodeEqual("Zm8=", "fo", options); + decodeEqual("Zm9v", "foo", options); + decodeEqual("Zm9vYg==", "foob", options); + decodeEqual("Zm9vYmE=", "fooba", options); + decodeEqual("Zm9vYmFy", "foobar", options); + + decodeEqual("8J-kkw==", "🤓", options); + decodeEqual("8J-kk2Zvb_CflpY=", "🤓foo🖖", options); + + decodeEqual("b2g_", "oh?", options); }); test("stop-before-partial lastChunkHandling", () => {