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

Remove potential ending line break when using edebug() with LoggerInterface #3047

Merged
merged 3 commits into from
Apr 8, 2024

Conversation

axi
Copy link

@axi axi commented Apr 8, 2024

This PR is for #3045.

src/SMTP.php Outdated
@@ -280,6 +280,8 @@ protected function edebug($str, $level = 0)
}
//Is this a PSR-3 logger?
if ($this->Debugoutput instanceof \Psr\Log\LoggerInterface) {
//Remove ending line breaks potentialy added by calls to SMTP::client_send()
$str = preg_replace('/[' . static::LE .']+$/', '', $str);
Copy link
Member

Choose a reason for hiding this comment

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

Instead of that static::LE, this should use an explicit \r\n as we are matching individual meta characters in a character class, not a literal string. static::LE contains a literal "\r\n" which represents actual CR and LF chars, not their meta-equivalents. Basically do what the other debug output options do.

Copy link
Member

Choose a reason for hiding this comment

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

This would also fail the code style check, which requires spaces either side of string concat . chars, but that's academic as you won't need to do concat with the above change.

src/SMTP.php Outdated
@@ -280,6 +280,8 @@ protected function edebug($str, $level = 0)
}
//Is this a PSR-3 logger?
if ($this->Debugoutput instanceof \Psr\Log\LoggerInterface) {
//Remove ending line breaks potentialy added by calls to SMTP::client_send()
$str = preg_replace('/[\r\n]+$/', '', $str);
Copy link
Contributor

Choose a reason for hiding this comment

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

Just wondering - could/should this be simplified to rtrim($str, "\r\n") ?

Copy link
Author

@axi axi Apr 8, 2024

Choose a reason for hiding this comment

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

my IDE was suggesting the same :-)

Copy link
Member

Choose a reason for hiding this comment

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

Yep, that seems reasonable – and it could be used in the other cases as well. I expect it will be marginally faster, but I don't think optimising debugging output is really something to worry about!

@Synchro Synchro merged commit 400aeae into PHPMailer:master Apr 8, 2024
17 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants