Skip to content
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
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,6 @@ parameters:
count: 1
path: src/Options.php

-
message: "#^Method Sentry\\\\Options\\:\\:getMaxValueLength\\(\\) should return int but returns mixed\\.$#"
count: 1
path: src/Options.php

-
message: "#^Method Sentry\\\\Options\\:\\:getOrgId\\(\\) should return int\\|null but returns mixed\\.$#"
count: 1
Expand Down
24 changes: 0 additions & 24 deletions src/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -935,28 +935,6 @@ public function setDefaultIntegrations(bool $enable): self
return $this;
}

/**
* Gets the max length for values in the event payload.
*/
public function getMaxValueLength(): int
{
return $this->options['max_value_length'];
}

/**
* Sets the max length for specific values in the event payload.
*
* @param int $maxValueLength The number of characters after which the values containing text will be truncated
*/
public function setMaxValueLength(int $maxValueLength): self
{
$options = array_merge($this->options, ['max_value_length' => $maxValueLength]);

$this->options = $this->resolver->resolve($options);

return $this;
}

/**
* Gets the http proxy setting.
*/
Expand Down Expand Up @@ -1271,7 +1249,6 @@ private function configureOptions(OptionsResolver $resolver): void
'in_app_exclude' => [],
'in_app_include' => [],
'send_default_pii' => false,
'max_value_length' => 1024,
'transport' => null,
'http_client' => null,
'http_proxy' => null,
Expand Down Expand Up @@ -1320,7 +1297,6 @@ private function configureOptions(OptionsResolver $resolver): void
$resolver->setAllowedTypes('integrations', ['Sentry\\Integration\\IntegrationInterface[]', 'callable']);
$resolver->setAllowedTypes('send_default_pii', 'bool');
$resolver->setAllowedTypes('default_integrations', 'bool');
$resolver->setAllowedTypes('max_value_length', 'int');
$resolver->setAllowedTypes('transport', ['null', TransportInterface::class]);
$resolver->setAllowedTypes('http_client', ['null', HttpClientInterface::class]);
$resolver->setAllowedTypes('http_proxy', ['null', 'string']);
Expand Down
4 changes: 0 additions & 4 deletions src/Serializer/AbstractSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,6 @@ protected function serializeString(string $value): string
$encoded = mb_convert_encoding($value, 'UTF-8') ?: '<encoding error>';
}

if (mb_strlen($encoded) > $this->options->getMaxValueLength()) {
$encoded = mb_substr($encoded, 0, $this->options->getMaxValueLength() - 10, 'UTF-8') . ' {clipped}';
}

return $encoded;
}

Expand Down
7 changes: 0 additions & 7 deletions tests/OptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,13 +320,6 @@ static function (): void {},
'setDefaultIntegrations',
];

yield [
'max_value_length',
50,
'getMaxValueLength',
'setMaxValueLength',
];

yield [
'transport',
new HttpTransport(new Options(), new HttpClient('foo', 'bar'), new PayloadSerializer(new Options())),
Expand Down
20 changes: 0 additions & 20 deletions tests/Serializer/AbstractSerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,26 +393,6 @@ public function testBrokenEncoding(bool $serializeAllObjects): void
}
}

/**
* @dataProvider serializeAllObjectsDataProvider
*/
public function testLongString(bool $serializeAllObjects): void
{
$serializer = $this->createSerializer();

if ($serializeAllObjects) {
$serializer->setSerializeAllObjects(true);
}

foreach ([100, 1000, 1010, 1024, 1050, 1100, 10000] as $length) {
$input = str_repeat('x', $length);
$result = $this->invokeSerialization($serializer, $input);

$this->assertIsString($result);
$this->assertLessThanOrEqual(1024, \strlen($result));
}
}
Comment on lines -399 to -414
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also change this to $this->assertLessThanOrEqual($length, \strlen($result)); which is admittedly a bit goofy but it would test that truncation is not applied.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed this would be a bit goofy. Don't think we need to test this specifically.


/**
* @dataProvider serializeAllObjectsDataProvider
*/
Expand Down
24 changes: 0 additions & 24 deletions tests/Serializer/SerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,30 +201,6 @@ public function testSerializableObjectThatThrowsAnException(): void
$this->assertEquals('Object ' . \get_class($object), $this->invokeSerialization($serializer, $object));
}

public function testLongStringWithOverwrittenMessageLength(): void
{
$serializer = $this->createSerializer(new Options(['max_value_length' => 500]));

foreach ([100, 490, 499, 500, 501, 1000, 10000] as $length) {
$input = str_repeat('x', $length);
$result = $this->invokeSerialization($serializer, $input);

$this->assertIsString($result);
$this->assertLessThanOrEqual(500, \strlen($result));
}
}

public function testClippingUTF8Characters(): void
{
$serializer = $this->createSerializer(new Options(['max_value_length' => 19]));

$clipped = $this->invokeSerialization($serializer, 'Прекратите надеяться, что ваши пользователи будут сообщать об ошибках');

$this->assertSame('Прекратит {clipped}', $clipped);
$this->assertNotNull(json_encode($clipped));
$this->assertSame(\JSON_ERROR_NONE, json_last_error());
}

/**
* @return Serializer
*/
Expand Down
Loading