Skip to content

Commit

Permalink
Correctly handle case where a metadata key is called 'metadata'
Browse files Browse the repository at this point in the history
  • Loading branch information
ob-stripe committed Mar 11, 2019
1 parent 0d9e277 commit 801ad85
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/StripeObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public function updateAttributes($values, $opts = null, $dirty = true)
// This is necessary in case metadata is empty, as PHP arrays do
// not differentiate between lists and hashes, and we consider
// empty arrays to be lists.
if ($k === "metadata") {
if (($k === "metadata") && (is_array($v))) {
$this->_values[$k] = StripeObject::constructFrom($v, $opts);
} else {
$this->_values[$k] = Util\Util::convertToStripeObject($v, $opts);
Expand Down
10 changes: 10 additions & 0 deletions tests/Stripe/StripeObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -473,4 +473,14 @@ public function testIsDeleted()
$obj = StripeObject::constructFrom(['deleted' => true]);
$this->assertTrue($obj->isDeleted());
}

public function testDeserializeMetadataKeyNamedMetadata()
{
$obj = StripeObject::constructFrom([
'metadata' => ['metadata' => 'value'],
]);

$this->assertInstanceOf("Stripe\\StripeObject", $obj->metadata);
$this->assertEquals("value", $obj->metadata->metadata);
}
}

0 comments on commit 801ad85

Please sign in to comment.