Skip to content

Commit

Permalink
Escape control characters
Browse files Browse the repository at this point in the history
  • Loading branch information
cleptric committed Apr 4, 2024
1 parent c080bae commit 41c677b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/Serializer/EnvelopItems/MetricsItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,17 @@ private static function replaceTagValueCharacters(string $tagValue): string
{
$tagValue = str_replace(
[
"\n",
"\r",
"\t",
'\\',
'|',
',',
],
[
'\n',
'\r',
'\t',
'\\\\',
'\u{7c}',
'\u{2c}',
Expand Down
6 changes: 3 additions & 3 deletions tests/Serializer/EnvelopeItems/MetricsItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function testToEnvelopeItem(Event $event, string $expectedResult): void
public static function toEnvelopeItemDataProvider(): iterable
{
$metric = new CounterType('abcABC123_-./äöü$%&abcABC123', 1.0, MetricsUnit::custom('abcABC123_-./äöü$%&abcABC123'), [
'abcABC123_-./äöü$%&abcABC123' => 'abc|,\\123',
'abcABC123_-./äöü$%&abcABC123' => "abc\n\r\t|,\\123",
], 1597790835);

$event = Event::createMetrics(new EventId('fc9442f5aef34234bb22b9a615e30ccd'));
Expand All @@ -43,8 +43,8 @@ public static function toEnvelopeItemDataProvider(): iterable
yield [
$event,
<<<TEXT
{"type":"statsd","length":103}
abcABC123_-._abcABC123@abcABC123_abcABC123:1|c|#abcABC123_-./abcABC123:abc\\u{7c}\\u{2c}\\\\123|T1597790835
{"type":"statsd","length":112}
abcABC123_-._abcABC123@abcABC123_abcABC123:1|c|#abcABC123_-./abcABC123:abc\\n\\r\\t\\u{7c}\\u{2c}\\\\123|T1597790835
TEXT
,
];
Expand Down

0 comments on commit 41c677b

Please sign in to comment.