Skip to content

Commit e27a4db

Browse files
bjoriderickr
authored andcommitted
Include numeric keys as well
1 parent f531d4a commit e27a4db

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/bson.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,9 +1071,10 @@ PHONGO_API void zval_to_bson(zval *data, php_phongo_bson_flags_t flags, bson_t *
10711071
#if PHP_VERSION_ID >= 70000
10721072
{
10731073
zend_string *key;
1074+
zend_ulong num_key;
10741075
zval *value;
10751076

1076-
ZEND_HASH_FOREACH_STR_KEY_VAL(ht_data, key, value) {
1077+
ZEND_HASH_FOREACH_KEY_VAL(ht_data, num_key, key, value) {
10771078
if (key) {
10781079
if (Z_TYPE_P(data) == IS_OBJECT) {
10791080
const char *skey;
@@ -1088,9 +1089,14 @@ PHONGO_API void zval_to_bson(zval *data, php_phongo_bson_flags_t flags, bson_t *
10881089
}
10891090
phongo_bson_append(bson, flags & ~PHONGO_BSON_ADD_ID, skey, skey_len, Z_TYPE_P(value), value TSRMLS_CC);
10901091
} else {
1091-
/* Chop off the \0 from string lengths */
1092-
phongo_bson_append(bson, flags & ~PHONGO_BSON_ADD_ID, key->val, key->len-1, Z_TYPE_P(value), value TSRMLS_CC);
1092+
phongo_bson_append(bson, flags & ~PHONGO_BSON_ADD_ID, key->val, key->len, Z_TYPE_P(value), value TSRMLS_CC);
10931093
}
1094+
} else {
1095+
char numbuf[32];
1096+
const char *skey;
1097+
unsigned int skey_len = 0;
1098+
skey_len = bson_uint32_to_string(num_key, (const char **)&skey, numbuf, sizeof(numbuf));
1099+
phongo_bson_append(bson, flags & ~PHONGO_BSON_ADD_ID, skey, skey_len, Z_TYPE_P(value), value TSRMLS_CC);
10941100
}
10951101
} ZEND_HASH_FOREACH_END();
10961102
}

0 commit comments

Comments
 (0)