Skip to content

Commit

Permalink
Correct handling of null in user_context (fixes GH-388)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcramer committed Dec 14, 2016
1 parent b9e7b00 commit ba5e24c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/Raven/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,10 @@ public function onShutdown()
public function user_context($data, $merge=true)
{
if ($merge && $this->context->user !== null) {
// bail if data is null
if (!$data) {
return;
}
$this->context->user = array_merge($this->context->user, $data);
} else {
$this->context->user = $data;
Expand Down
7 changes: 7 additions & 0 deletions test/Raven/Tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,13 @@ public function testUserContextWithMerge()
$this->assertEquals($client->context->user, array('foo' => 'bar', 'baz' => 'bar'));
}

public function testUserContextWithMergeAndNull()
{
$client = new Dummy_Raven_Client();
$client->user_context(array('foo' => 'bar'), true);
$client->user_context(null, true);
$this->assertEquals($client->context->user, array('foo' => 'bar'));
}

/**
* Set the server array to the test values, check the current url
Expand Down

0 comments on commit ba5e24c

Please sign in to comment.