Skip to content

Commit

Permalink
JsonParser: "" is an empty string, not a null value
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomekling committed Aug 14, 2019
1 parent f6fe56d commit 1ac963b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion AK/JsonParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ String JsonParser::consume_quoted_string()
consume_specific('"');

if (buffer.is_empty())
return {};
return String::empty();

auto& last_string_starting_with_character = m_last_string_starting_with_character[(int)buffer.first()];
if (last_string_starting_with_character.length() == buffer.size()) {
Expand Down
8 changes: 8 additions & 0 deletions AK/Tests/TestJSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,12 @@ BENCHMARK_CASE(load_4chan_catalog)
}
}

TEST_CASE(json_empty_string)
{
auto json = JsonValue::from_string("\"\"");
EXPECT_EQ(json.type(), JsonValue::Type::String);
EXPECT_EQ(json.as_string().is_null(), false);
EXPECT_EQ(json.as_string().is_empty(), true);
}

TEST_MAIN(JSON)

0 comments on commit 1ac963b

Please sign in to comment.