diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fb1662db8..0147896c76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ ### Fixed * ([#????](https://github.com/realm/realm-core/issues/????), since v?.?.?) -* None. +* Using an empty KeyPath in C API would result in no filtering being done ([#7805](https://github.com/realm/realm-core/issues/7805)) ### Breaking changes * None. diff --git a/src/realm/object-store/c_api/notifications.cpp b/src/realm/object-store/c_api/notifications.cpp index 5bb041f35f..0f5bcc9271 100644 --- a/src/realm/object-store/c_api/notifications.cpp +++ b/src/realm/object-store/c_api/notifications.cpp @@ -67,7 +67,7 @@ struct DictionaryNotificationsCallback { std::optional build_key_path_array(realm_key_path_array_t* key_path_array) { std::optional ret; - if (key_path_array && key_path_array->size()) { + if (key_path_array) { ret.emplace(std::move(*key_path_array)); } return ret; diff --git a/test/object-store/c_api/c_api.cpp b/test/object-store/c_api/c_api.cpp index fa11f1f294..fbbfd7518b 100644 --- a/test/object-store/c_api/c_api.cpp +++ b/test/object-store/c_api/c_api.cpp @@ -3130,6 +3130,7 @@ TEST_CASE("C API - properties", "[c_api]") { SECTION("Embedded objects") { realm_property_info_t info; bool found = false; + bool to_be_called = true; realm_key_path_array_t* key_path_array = nullptr; realm_find_property(realm, class_bar.key, "sub", &found, &info); auto bar_sub_key = info.key; @@ -3140,11 +3141,14 @@ TEST_CASE("C API - properties", "[c_api]") { embedded = cptr_checked(realm_set_embedded(obj2.get(), bar_sub_key)); }); + SECTION("using empty keypath") { + const char* bar_strings[1] = {""}; + key_path_array = realm_create_key_path_array(realm, class_bar.key, 0, bar_strings); + to_be_called = false; + } SECTION("using valid nesting") { - const char* bar_strings[1] = {"sub.int"}; key_path_array = realm_create_key_path_array(realm, class_bar.key, 1, bar_strings); - REQUIRE(key_path_array); } SECTION("using star notation") { const char* bar_strings[1] = {"*.int"}; @@ -3160,12 +3164,14 @@ TEST_CASE("C API - properties", "[c_api]") { checked(realm_refresh(realm, nullptr)); state.called = false; + state.changes = nullptr; write([&]() { checked(realm_set_value(embedded.get(), embedded_int_key, rlm_int_val(999), false)); }); - REQUIRE(state.called); + REQUIRE(state.called == to_be_called); CHECK(!state.error); - CHECK(state.changes); + if (to_be_called) + CHECK(state.changes); } SECTION("using backlink") { const char* bar_strings[1] = {"linking_objects.public_int"};