Skip to content

Commit b218b37

Browse files
committed
Merge pull request #61
2 parents 8789ef4 + cf59c4a commit b218b37

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/bson.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
/* PHP Core stuff */
2929
#include <php.h>
3030
#include <ext/spl/spl_array.h>
31+
#include <Zend/zend_hash.h>
3132
#include <Zend/zend_interfaces.h>
3233

3334
/* PHP array helpers */
@@ -789,6 +790,7 @@ PHONGO_API void zval_to_bson(zval *data, php_phongo_bson_flags_t flags, bson_t *
789790
if (instanceof_function(Z_OBJCE_P(data), php_phongo_persistable_ce TSRMLS_CC)) {
790791
if (flags & PHONGO_BSON_ADD_ODS) {
791792
bson_append_binary(bson, PHONGO_ODM_FIELD_NAME, -1, 0x80, (const uint8_t *)Z_OBJCE_P(data)->name, strlen(Z_OBJCE_P(data)->name));
793+
zend_hash_del(ht_data, PHONGO_ODM_FIELD_NAME, sizeof(PHONGO_ODM_FIELD_NAME));
792794
}
793795
}
794796

tests/bson/bug0334.phpt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
PHPC-334: Injected __pclass should override a __pclass key in bsonSerialize() return value
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"?>
5+
--FILE--
6+
<?php
7+
use MongoDB\BSON as BSON;
8+
9+
require_once __DIR__ . "/../utils/basic.inc";
10+
11+
class MyClass implements BSON\Persistable {
12+
function bsonSerialize() {
13+
return array(
14+
"foo" => "bar",
15+
"__pclass" => "baz",
16+
);
17+
}
18+
function bsonUnserialize(array $data) {
19+
}
20+
}
21+
22+
hex_dump(fromPHP(new MyClass));
23+
24+
?>
25+
===DONE===
26+
<?php exit(0); ?>
27+
--EXPECT--
28+
0 : 28 00 00 00 05 5f 5f 70 63 6c 61 73 73 00 07 00 [(....__pclass...]
29+
10 : 00 00 80 4d 79 43 6c 61 73 73 02 66 6f 6f 00 04 [...MyClass.foo..]
30+
20 : 00 00 00 62 61 72 00 00 [...bar..]
31+
===DONE===

0 commit comments

Comments
 (0)