Skip to content

Commit c80ce3e

Browse files
kevin1018acmorrow
authored andcommitted
CXX-1476 Fix compare key name error
If a document has a "de" key and a "desc" key, when searching for the "de" key, it may match the "desc" key. So judge the key length to make sure match the right key.
1 parent 362f7ec commit c80ce3e

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/bsoncxx/document/view.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ view::const_iterator view::find(stdx::string_view key) const {
125125

126126
while (bson_iter_next(&iter)) {
127127
const char* ikey = bson_iter_key(&iter);
128-
if (0 == strncmp(key.data(), ikey, key.size())) {
128+
if (0 == strncmp(key.data(), ikey, key.size()) && strlen(ikey) == key.size()) {
129129
return const_iterator(element(iter.raw, iter.len, iter.off));
130130
}
131131
}

src/mongocxx/test/collection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2336,7 +2336,7 @@ TEST_CASE("create_index tests", "[collection]") {
23362336

23372337
bool unique = options.unique().value();
23382338
auto validate = [unique](bsoncxx::document::view index) {
2339-
auto expire_after = index["expireAfter"];
2339+
auto expire_after = index["expireAfterSeconds"];
23402340
REQUIRE(expire_after);
23412341
REQUIRE(expire_after.type() == type::k_int32);
23422342
REQUIRE(expire_after.get_int32().value == 500);

0 commit comments

Comments
 (0)