From 0739f1b1e6ec09250b415e1efa3cdf6a038e2181 Mon Sep 17 00:00:00 2001 From: stelar7 Date: Fri, 4 Oct 2024 00:15:30 +0200 Subject: [PATCH] LibWeb: Iterate over utf8 codepoints when checking validity --- Userland/Libraries/LibWeb/MimeSniff/MimeType.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibWeb/MimeSniff/MimeType.cpp b/Userland/Libraries/LibWeb/MimeSniff/MimeType.cpp index 11cad3bb2cd..0da85956340 100644 --- a/Userland/Libraries/LibWeb/MimeSniff/MimeType.cpp +++ b/Userland/Libraries/LibWeb/MimeSniff/MimeType.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -33,9 +34,8 @@ static bool contains_only_http_quoted_string_token_code_points(StringView string // https://mimesniff.spec.whatwg.org/#http-quoted-string-token-code-point // An HTTP quoted-string token code point is U+0009 TAB, a code point in the range U+0020 SPACE to U+007E (~), inclusive, // or a code point in the range U+0080 through U+00FF (ΓΏ), inclusive. - for (char ch : string) { - // NOTE: This doesn't check for ch <= 0xFF, as ch is 8-bits and so that condition will always be true. - if (!(ch == '\t' || (ch >= 0x20 && ch <= 0x7E) || (u8)ch >= 0x80)) + for (auto ch : Utf8View(string)) { + if (!(ch == '\t' || (ch >= 0x20 && ch <= 0x7E) || (ch >= 0x80 && ch <= 0xFF))) return false; } return true;