mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-28 21:54:40 +03:00
AK: Fix JSON parser crashing when encountering UTF-8
The mechanism that caches the most recently seen string for each first character was indexing into the cache using a 'char' subscript. Oops!
This commit is contained in:
parent
d1d7db2745
commit
821484f170
Notes:
sideshowbarker
2024-07-19 10:33:28 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/821484f1700
@ -103,7 +103,7 @@ String JsonParser::consume_quoted_string()
|
||||
if (buffer.is_empty())
|
||||
return String::empty();
|
||||
|
||||
auto& last_string_starting_with_character = m_last_string_starting_with_character[(int)buffer.first()];
|
||||
auto& last_string_starting_with_character = m_last_string_starting_with_character[(u8)buffer.first()];
|
||||
if (last_string_starting_with_character.length() == (size_t)buffer.size()) {
|
||||
if (!memcmp(last_string_starting_with_character.characters(), buffer.data(), buffer.size()))
|
||||
return last_string_starting_with_character;
|
||||
|
@ -74,4 +74,12 @@ TEST_CASE(json_empty_string)
|
||||
EXPECT_EQ(json.as_string().is_empty(), true);
|
||||
}
|
||||
|
||||
TEST_CASE(json_utf8_character)
|
||||
{
|
||||
auto json = JsonValue::from_string("\"\xc3\x84\"");
|
||||
EXPECT_EQ(json.type(), JsonValue::Type::String);
|
||||
EXPECT_EQ(json.as_string().is_null(), false);
|
||||
EXPECT_EQ(json.as_string().length(), 2);
|
||||
}
|
||||
|
||||
TEST_MAIN(JSON)
|
||||
|
Loading…
Reference in New Issue
Block a user