summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bson/bson.c9
-rw-r--r--src/ejdb/tests/ejdbtest2.c64
2 files changed, 65 insertions, 8 deletions
diff --git a/src/bson/bson.c b/src/bson/bson.c
index 64069e2..b192f2d 100644
--- a/src/bson/bson.c
+++ b/src/bson/bson.c
@@ -1404,13 +1404,8 @@ static void bson_append_fpath_from_iterator(const char *fpath, const bson_iterat
bson_append_finish_object(into); //arrays are covered also
}
} else { //intermediate part
- if (bson_isnumstr(key, keylen)) {
- nl++;
- bson_append_start_array2(into, key, keylen);
- } else {
- nl++;
- bson_append_start_object2(into, key, keylen);
- }
+ nl++;
+ bson_append_start_object2(into, key, keylen);
}
fp = rp;
}
diff --git a/src/ejdb/tests/ejdbtest2.c b/src/ejdb/tests/ejdbtest2.c
index 1924732..40d2f8c 100644
--- a/src/ejdb/tests/ejdbtest2.c
+++ b/src/ejdb/tests/ejdbtest2.c
@@ -6148,6 +6148,67 @@ void testTicket156(void) {
tclistdel(q1res);
}
+void testTicket161(void) {
+ EJCOLL *coll = ejdbcreatecoll(jb, "ticket161", NULL);
+ CU_ASSERT_PTR_NOT_NULL_FATAL(coll);
+
+ bson b;
+ bson_oid_t oid;
+
+ bson_init(&b);
+ bson_append_start_object(&b, "stocks");
+ bson_append_finish_object(&b);
+ bson_finish(&b);
+ CU_ASSERT_TRUE(ejdbsavebson(coll, &b, &oid));
+ bson_destroy(&b);
+
+ bson bsq;
+ bson_init_as_query(&bsq);
+ bson_append_start_object(&bsq, "$inc");
+ bson_append_int(&bsq, "stocks.s72851.qty", 4);
+ bson_append_finish_object(&bsq);
+ bson_finish(&bsq);
+ CU_ASSERT_FALSE_FATAL(bsq.err);
+
+ uint32_t count = ejdbupdate(coll, &bsq, 0, 0, 0, 0);
+ bson_destroy(&bsq);
+ CU_ASSERT_EQUAL(count, 1);
+
+ bson_init_as_query(&bsq);
+ bson_finish(&bsq);
+
+ EJQ *q1 = ejdbcreatequery(jb, &bsq, NULL, 0, NULL);
+ CU_ASSERT_PTR_NOT_NULL_FATAL(q1);
+ TCLIST *q1res = ejdbqryexecute(coll, q1, &count, 0, NULL);
+ CU_ASSERT_EQUAL(TCLISTNUM(q1res), 1);
+
+ void *bsdata = TCLISTVALPTR(q1res, 0);
+ CU_ASSERT_PTR_NOT_NULL_FATAL(bsdata);
+
+ bson_iterator it, sit1, sit2;
+ bson_type bt;
+ BSON_ITERATOR_FROM_BUFFER(&it, bsdata);
+
+ while ((bt = bson_iterator_next(&it)) != BSON_EOO) {
+ if (bt == BSON_OBJECT) {
+ break;
+ }
+ }
+ CU_ASSERT_EQUAL_FATAL(bt, BSON_OBJECT);
+
+ BSON_ITERATOR_SUBITERATOR(&it, &sit1);
+ bt = bson_iterator_next(&sit1);
+ CU_ASSERT_EQUAL(bt, BSON_OBJECT);
+
+ BSON_ITERATOR_SUBITERATOR(&sit1, &sit2);
+ bt = bson_iterator_next(&sit2);
+ CU_ASSERT_TRUE(BSON_IS_NUM_TYPE(bt));
+
+ bson_destroy(&bsq);
+ ejdbquerydel(q1);
+ tclistdel(q1res);
+}
+
int main() {
setlocale(LC_ALL, "en_US.UTF-8");
CU_pSuite pSuite = NULL;
@@ -6243,7 +6304,8 @@ int main() {
(NULL == CU_add_test(pSuite, "testTicket117", testTicket117)) ||
(NULL == CU_add_test(pSuite, "testMetaInfo", testMetaInfo)) ||
(NULL == CU_add_test(pSuite, "testTicket148", testTicket148)) ||
- (NULL == CU_add_test(pSuite, "testTicket156", testTicket156))
+ (NULL == CU_add_test(pSuite, "testTicket156", testTicket156)) ||
+ (NULL == CU_add_test(pSuite, "testTicket161", testTicket161))
) {
CU_cleanup_registry();
return CU_get_error();