1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:37:37 +00:00

AK: Ensure short String instances are valid UTF-8

We are currently only validating long strings.
This commit is contained in:
Timothy Flynn 2023-03-03 09:03:45 -05:00 committed by Tim Flynn
parent 434ca78425
commit da0d000909
3 changed files with 37 additions and 15 deletions

View file

@ -20,6 +20,7 @@
#include <AK/Traits.h>
#include <AK/Types.h>
#include <AK/UnicodeUtils.h>
#include <AK/Utf8View.h>
#include <AK/Vector.h>
namespace AK {
@ -72,6 +73,7 @@ public:
static AK_SHORT_STRING_CONSTEVAL String from_utf8_short_string(StringView string)
{
VERIFY(string.length() <= MAX_SHORT_STRING_BYTE_COUNT);
VERIFY(Utf8View { string }.validate());
ShortString short_string;
for (size_t i = 0; i < string.length(); ++i)