Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F503689
D209.1745911739.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D209.1745911739.diff
View Options
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
Details
Attached
Mime Type
text/plain
Expires
Tue, Apr 29, 12:28 AM (15 h, 9 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
109926
Default Alt Text
D209.1745911739.diff (2 KB)
Attached To
Mode
D209: Fix crash when a room hero's display name is not a string
Attached
Detach File
Event Timeline
Log In to Comment