Skip to content

Commit 0ae5692

Browse files
committed
Always normalize context line endings
Normalizes line endings in all context values immediately after JSON extraction, ensuring consistent cross-platform behavior regardless of whether filtering is enabled.
1 parent 1cef6f7 commit 0ae5692

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/Logs/LaravelLog.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ protected function parseText(array &$matches = []): void
2626
$length = strlen($this->text);
2727

2828
$this->extractContextsFromFullText();
29+
$this->normalizeContextLineEndings();
2930

3031
$this->extra['log_size'] = $length;
3132
$this->extra['log_size_formatted'] = Utils::bytesForHumans($length);
@@ -191,6 +192,19 @@ protected function getJsonStringsFromFullText(): array
191192
return $json_strings;
192193
}
193194

195+
protected function normalizeContextLineEndings(): void
196+
{
197+
if (empty($this->context)) {
198+
return;
199+
}
200+
201+
foreach ($this->context as $key => $value) {
202+
if (is_string($value)) {
203+
$this->context[$key] = str_replace(["\r\n", "\r"], "\n", $value);
204+
}
205+
}
206+
}
207+
194208
protected function filterStackTrace(string $text): string
195209
{
196210
// Normalize line endings for cross-platform compatibility

tests/Unit/LaravelLogs/LaravelLogsTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,8 @@
311311

312312
$log = new LaravelLog($logText);
313313

314-
// Normalize line endings for cross-platform comparison
315-
$normalizedContext = str_replace(["\r\n", "\r"], "\n", $log->context['exception']);
316-
317314
expect($log->context)->toHaveKey('exception')
318-
->and($normalizedContext)->toBe($stackTrace)
315+
->and($log->context['exception'])->toBe($stackTrace)
319316
->and($log->context['exception'])->toContain('/vendor/symfony/http-kernel/')
320317
->and($log->context['exception'])->toContain('/vendor/laravel/framework/');
321318
});

0 commit comments

Comments
 (0)