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.
This commit is contained in:
Arda Cinar 2023-01-10 11:53:44 +03:00 committed by Linus Groh
parent 283187afc5
commit 4d335f3819
Notes: sideshowbarker 2024-07-17 06:20:50 +09:00

View file

@ -8,9 +8,11 @@
#include <AK/ByteBuffer.h>
#include <AK/CharacterTypes.h>
#include <AK/Error.h>
#include <AK/StringBuilder.h>
#include <AK/StringView.h>
#include <AK/Vector.h>
#include <LibWeb/Infra/Base64.h>
#include <LibWeb/Infra/CharacterTypes.h>
namespace Web::Infra {
@ -18,7 +20,13 @@ namespace Web::Infra {
ErrorOr<ByteBuffer> 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 datas code point length divides by 4 leaving no remainder, then:
if (data.length() % 4 == 0) {