Page MenuHomePhorge

D209.1745891118.diff
No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None

D209.1745891118.diff

diff --git a/src/client/room/room.cpp b/src/client/room/room.cpp
--- a/src/client/room/room.cpp
+++ b/src/client/room/room.cpp
@@ -245,7 +245,7 @@
immer::flex_vector<std::string>{},
zug::map([](const auto &event) {
auto content = event.content();
- return content.get().contains("displayname")
+ return content.get().contains("displayname") && content.get()["displayname"].is_string()
? content.get()["displayname"].template get<std::string>()
: std::string();
}),
diff --git a/src/tests/client/room-test.cpp b/src/tests/client/room-test.cpp
--- a/src/tests/client/room-test.cpp
+++ b/src/tests/client/room-test.cpp
@@ -7,7 +7,7 @@
#include <libkazv-config.hpp>
#include <catch2/catch_all.hpp>
-
+#include <catch2/matchers/catch_matchers_range_equals.hpp>
#include <lager/event_loop/boost_asio.hpp>
#include <boost/asio.hpp>
@@ -92,7 +92,7 @@
"event_id": "some id3",
"room_id": "!example:example.org",
"type": "m.room.member",
- "state_key": "@foo:example.org"
+ "state_key": "@bar:example.org"
})"_json);
static auto exampleRoomWithoutNameEvent()
@@ -214,18 +214,22 @@
TEST_CASE("Room::heroDisplayNames()", "[client][room][getter]")
{
- auto room = makeRoomWithDumbContext(exampleRoomWithNameEvent());
+ auto r = exampleRoomWithNameEvent();
THEN("it should give out the names") {
+ auto room = makeRoomWithDumbContext(r);
auto val = room.heroDisplayNames().make().get();
- REQUIRE(val.size() == 2);
- REQUIRE(std::any_of(val.begin(), val.end(),
- [](const auto &v) {
- return v == "foo's name";
- }));
- REQUIRE(std::any_of(val.begin(), val.end(),
- [](const auto &v) {
- return v == "bar's name";
- }));
+ REQUIRE_THAT(val, Catch::Matchers::UnorderedRangeEquals(
+ immer::flex_vector<std::string>{"foo's name", "bar's name"}));
+ }
+
+ THEN("it should not crash when name is not a string") {
+ auto bar = memberBar.originalJson().get();
+ bar["content"]["displayname"] = 3;
+ withRoomState({Event(bar)})(r);
+ auto room = makeRoomWithDumbContext(r);
+ auto val = room.heroDisplayNames().make().get();
+ REQUIRE_THAT(val, Catch::Matchers::UnorderedRangeEquals(
+ immer::flex_vector<std::string>{"foo's name", ""}));
}
}

File Metadata

Mime Type
text/plain
Expires
Mon, Apr 28, 6:45 PM (14 h, 53 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
109926
Default Alt Text
D209.1745891118.diff (2 KB)

Event Timeline