Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it possible to overwrite message limit of 1024 #559

Merged
merged 1 commit into from
Apr 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions lib/Raven/Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,26 @@ class Raven_Serializer
*/
protected $mb_detect_order = self::DEFAULT_MB_DETECT_ORDER;

/**
* The default maximum message lengths. Longer strings will be truncated
*
* @var int
*/
protected $message_limit = Raven_Client::MESSAGE_LIMIT;

/**
* @param null|string $mb_detect_order
* @param null|int $message_limit
*/
public function __construct($mb_detect_order = null)
public function __construct($mb_detect_order = null, $message_limit = null)
{
if ($mb_detect_order != null) {
$this->mb_detect_order = $mb_detect_order;
}

if ($message_limit != null) {
$this->message_limit = (int) $message_limit;
}
}

/**
Expand Down Expand Up @@ -93,8 +105,8 @@ protected function serializeString($value)
}
}

if (strlen($value) > 1024) {
$value = substr($value, 0, 1014) . ' {clipped}';
if (strlen($value) > $this->message_limit) {
$value = substr($value, 0, $this->message_limit - 10) . ' {clipped}';
}

return $value;
Expand Down Expand Up @@ -141,4 +153,22 @@ public function setMbDetectOrder($mb_detect_order)

return $this;
}

/**
* @return int
* @codeCoverageIgnore
*/
public function getMessageLimit()
{
return $this->message_limit;
}

/**
* @param int $message_limit
* @codeCoverageIgnore
*/
public function setMessageLimit($message_limit)
{
$this->message_limit = (int)$message_limit;
}
}
20 changes: 20 additions & 0 deletions test/Raven/Tests/SerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,26 @@ public function testLongString()
}
}

/**
* @covers Raven_Serializer::serializeString
*/
public function testLongStringWithOverwrittenMessageLength()
{
$serializer = new Raven_Serializer();
$serializer->setMessageLimit(500);
for ($i = 0; $i < 100; $i++) {
foreach (array(100, 490, 499, 500, 501, 1000, 10000) as $length) {
$input = '';
for ($i = 0; $i < $length; $i++) {
$input .= chr(mt_rand(0, 255));
}
$result = $serializer->serialize($input);
$this->assertInternalType('string', $result);
$this->assertLessThanOrEqual(500, strlen($result));
}
}
}

/**
* @covers Raven_Serializer::serializeValue
*/
Expand Down