Skip to content

Commit

Permalink
C API: Fix empty keypath issue
Browse files Browse the repository at this point in the history
  • Loading branch information
jedelbo committed Aug 15, 2024
1 parent c4b5cae commit b641e12
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

### Fixed
* <How do the end-user experience this issue? what was the impact?> ([#????](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.
Expand Down
2 changes: 1 addition & 1 deletion src/realm/object-store/c_api/notifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct DictionaryNotificationsCallback {
std::optional<KeyPathArray> build_key_path_array(realm_key_path_array_t* key_path_array)
{
std::optional<KeyPathArray> ret;
if (key_path_array && key_path_array->size()) {
if (key_path_array) {
ret.emplace(std::move(*key_path_array));
}
return ret;
Expand Down
14 changes: 10 additions & 4 deletions test/object-store/c_api/c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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"};
Expand All @@ -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"};
Expand Down

0 comments on commit b641e12

Please sign in to comment.