From 4d335f3819e72a4e9d42172e2b586b3f5995d190 Mon Sep 17 00:00:00 2001 From: Arda Cinar Date: Tue, 10 Jan 2023 11:53:44 +0300 Subject: [PATCH] LibWeb: Remove all whitespace from input in decode_forgiving_base64 Instead of only stripping it from the ends, since that's actually what the spec says. --- Userland/Libraries/LibWeb/Infra/Base64.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWeb/Infra/Base64.cpp b/Userland/Libraries/LibWeb/Infra/Base64.cpp index 7944b5e4271..898006b0def 100644 --- a/Userland/Libraries/LibWeb/Infra/Base64.cpp +++ b/Userland/Libraries/LibWeb/Infra/Base64.cpp @@ -8,9 +8,11 @@ #include #include #include +#include #include #include #include +#include namespace Web::Infra { @@ -18,7 +20,13 @@ namespace Web::Infra { ErrorOr decode_forgiving_base64(StringView input) { // 1. Remove all ASCII whitespace from data. - auto data = input.trim_whitespace(); + // FIXME: It is possible to avoid copying input here, it's just a bit tricky to remove the equal signs + StringBuilder builder; + for (auto character : input) { + if (!is_ascii_whitespace(character)) + TRY(builder.try_append(character)); + } + auto data = builder.string_view(); // 2. If data’s code point length divides by 4 leaving no remainder, then: if (data.length() % 4 == 0) {