From 6857b746237fda11fd006ce292bf775241a10cfc Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Fri, 27 Feb 2026 14:27:48 +0100 Subject: [PATCH] accept must accept unpadded data in atob according with https://infra.spec.whatwg.org/#forgiving-base64-decode --- src/browser/tests/window/window.html | 10 ++++++++++ src/browser/webapi/Window.zig | 23 +++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/browser/tests/window/window.html b/src/browser/tests/window/window.html index 5d36e74d..8a024089 100644 --- a/src/browser/tests/window/window.html +++ b/src/browser/tests/window/window.html @@ -75,6 +75,16 @@ testing.expectEqual('abc', atob('YWJj')); testing.expectEqual('0123456789', atob('MDEyMzQ1Njc4OQ==')); testing.expectEqual('The quick brown fox jumps over the lazy dog', atob('VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw==')); + + // atob must accept unpadded base64 (forgiving-base64 decode per HTML spec) + testing.expectEqual('a', atob('YQ')); // 2 chars, len%4==2, needs '==' + testing.expectEqual('ab', atob('YWI')); // 3 chars, len%4==3, needs '=' + testing.expectEqual('ceil', atob('Y2VpbA')); // 6 chars, len%4==2, needs '==' + + // length % 4 == 1 must still throw + testing.expectError('Error: InvalidCharacterError', () => { + atob('Y'); + });