diff --git a/AK/JsonValue.cpp b/AK/JsonValue.cpp index 074d7f1819..a1bc94ce55 100644 --- a/AK/JsonValue.cpp +++ b/AK/JsonValue.cpp @@ -230,6 +230,8 @@ void JsonValue::clear() #ifndef KERNEL ErrorOr JsonValue::from_string(StringView input) { + if (input.is_empty()) + return JsonValue(); return JsonParser(input).parse(); } #endif diff --git a/Tests/AK/TestJSON.cpp b/Tests/AK/TestJSON.cpp index aa1f8139a9..7f0cbab296 100644 --- a/Tests/AK/TestJSON.cpp +++ b/Tests/AK/TestJSON.cpp @@ -122,3 +122,9 @@ TEST_CASE(json_u64_roundtrip) EXPECT_EQ_FORCE(value.is_error(), false); EXPECT_EQ(value.value().as_u64(), big_value); } + +TEST_CASE(json_parse_empty_string) +{ + auto value = JsonValue::from_string(""); + EXPECT_EQ(value.value().is_null(), true); +}