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

Single-quoted strings with [ ] in Laravel Log interpreting escape characters (\r \n) #53482

Open
Yousha opened this issue Nov 12, 2024 · 2 comments

Comments

@Yousha
Copy link

Yousha commented Nov 12, 2024

Laravel Version

11.30.0

PHP Version

8.3.13 64bit TS

Database Driver & Version

No response

Description

When logging with single-quoted ' strings that containing escape characters like \r and [ ], they are being interpreted in the log output. This results in unexpected behavior, such as \r being converted to a carriage return, even though single-quoted strings in PHP treat backslashes as literal characters.

Using Illuminate\Support\Facades\Log
With default logging configuration.

Steps To Reproduce

1- Download and create a Laravel 11 application project. (https://laravel.com/docs/11.x)

2- In any route, controller, or model file, log a string using single-quotes with a backslash \r and bracket [ ].
Example:
Log::info('[MyNamespace\routes\non-web\application]');

3- Check the Laravel log file.

Expected output

local.INFO: [MyNamespace\routes\non-web\application]

Actual output

local.INFO: [MyNamespace
outes
on-web\application]

Copy link

Thank you for reporting this issue!

As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.

If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.

Thank you!

@cosmastech
Copy link
Contributor

I think the issue here is caused by this: https://github.com/Seldaek/monolog/blob/32e515fdc02cdafbe4593e30a9350d486b125b67/src/Monolog/Formatter/LineFormatter.php#L241

If the first character in the log is [ or { then it replaces those substrings with "\n"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants