Skip to content

Commit 3e0150e

Browse files
authored
Fix crash when calling JSONItem::GetAsMap() on non-object (#3838)
1 parent 40bf0c1 commit 3e0150e

File tree

2 files changed

+1
-3
lines changed

2 files changed

+1
-3
lines changed

CodeLite/JSON.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ JSONItem JSONItem::operator[](int index) const
182182

183183
std::unordered_map<std::string_view, JSONItem> JSONItem::GetAsMap() const
184184
{
185-
if (!m_json) {
185+
if (!m_json || !isObject()) {
186186
return {};
187187
}
188188

Tests/CodeliteTest/JsonTests.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,7 @@ TEST_CASE("array json")
217217
CHECK(!item.hasNamedObject("a"));
218218
CHECK(!item.namedObject("a").isOk());
219219
CHECK(!item["a"].isOk());
220-
#if 0 // crash
221220
CHECK(item.GetAsMap().empty());
222-
#endif
223221
}
224222

225223
TEST_CASE("object json")

0 commit comments

Comments
 (0)