Skip to content

Commit 1921d93

Browse files
committed
Merge pull request #20 from launchdarkly/jko/check-empty
Ensure that empty custom attributes are not serialized to json
2 parents 0008ead + d40ed02 commit 1921d93

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/LaunchDarkly/LDUser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public function toJSON() {
117117
if (isset($this->_lastName)) {
118118
$json['lastName'] = $this->_lastName;
119119
}
120-
if (isset($this->_custom)) {
120+
if (isset($this->_custom) && !empty($this->_custom)) {
121121
$json['custom'] = $this->_custom;
122122
}
123123
if (isset($this->_anonymous)) {

tests/LDUserTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ public function testCoerceLDUserKey() {
2121
$this->assertEquals("string", gettype($json['key']));
2222
}
2323

24+
public function testEmptyCustom() {
25+
$builder = new LDUserBuilder("[email protected]");
26+
$user = $builder->build();
27+
$json = $user->toJSON();
28+
$this->assertTrue(!isset($json['custom']));
29+
}
30+
2431
public function testLDUserSecondary() {
2532
$builder = new LDUserBuilder("[email protected]");
2633
$user = $builder->secondary("secondary")->build();

0 commit comments

Comments
 (0)