mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
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:
parent
283187afc5
commit
4d335f3819
Notes:
sideshowbarker
2024-07-17 06:20:50 +09:00
Author: https://github.com/kuzux Commit: https://github.com/SerenityOS/serenity/commit/4d335f3819 Pull-request: https://github.com/SerenityOS/serenity/pull/16711 Issue: https://github.com/SerenityOS/serenity/issues/16638 Reviewed-by: https://github.com/linusg Reviewed-by: https://github.com/nico Reviewed-by: https://github.com/trflynn89
1 changed files with 9 additions and 1 deletions
|
@ -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 data’s code point length divides by 4 leaving no remainder, then:
|
||||
if (data.length() % 4 == 0) {
|
||||
|
|
Loading…
Reference in a new issue