mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:17:44 +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
1 changed files with 9 additions and 1 deletions
|
@ -8,9 +8,11 @@
|
||||||
#include <AK/ByteBuffer.h>
|
#include <AK/ByteBuffer.h>
|
||||||
#include <AK/CharacterTypes.h>
|
#include <AK/CharacterTypes.h>
|
||||||
#include <AK/Error.h>
|
#include <AK/Error.h>
|
||||||
|
#include <AK/StringBuilder.h>
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#include <LibWeb/Infra/Base64.h>
|
#include <LibWeb/Infra/Base64.h>
|
||||||
|
#include <LibWeb/Infra/CharacterTypes.h>
|
||||||
|
|
||||||
namespace Web::Infra {
|
namespace Web::Infra {
|
||||||
|
|
||||||
|
@ -18,7 +20,13 @@ namespace Web::Infra {
|
||||||
ErrorOr<ByteBuffer> decode_forgiving_base64(StringView input)
|
ErrorOr<ByteBuffer> decode_forgiving_base64(StringView input)
|
||||||
{
|
{
|
||||||
// 1. Remove all ASCII whitespace from data.
|
// 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:
|
// 2. If data’s code point length divides by 4 leaving no remainder, then:
|
||||||
if (data.length() % 4 == 0) {
|
if (data.length() % 4 == 0) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue