Skip to content

Fix GH-25832: mb_encode_mimeheader() rejects null for $charset and $transfer_encoding - #25833

Open
thunderer wants to merge 1 commit into
php:PHP-8.4from
thunderer:fix/mb-encode-mimeheader-null
Open

thunderer wants to merge 1 commit into
php:PHP-8.4from
thunderer:fix/mb-encode-mimeheader-null

Conversation

@thunderer

Copy link
Copy Markdown
Contributor

Fixes GH-25832.

The stub declares ?string for $charset and $transfer_encoding, and the function handles a null $charset by using the mail charset of the current language, but both parameters were parsed with Z_PARAM_STR since 29b02bf, which replaced "s|S!s!sl". This parses them with Z_PARAM_STR_OR_NULL again. The test fails without the change.

… $transfer_encoding

The stub declares both parameters as ?string and the function treats a
null $charset as "use the mail charset of the current language", but
29b02bf parsed them with Z_PARAM_STR when it replaced "s|S!s!sl".
So null was deprecated and coerced to "", which is not a valid
$charset, and it threw a TypeError with strict_types. Parse both with
Z_PARAM_STR_OR_NULL again.
@alexdowad

Copy link
Copy Markdown
Contributor

@thunderer, thanks for the report. I hope some time soon to have a look at this issue and make sure I understand its background. Is it correct that the behavior of mb_encode_mimeheader was stable from when the function was added, and changed only in 29b02bf?

@thunderer

Copy link
Copy Markdown
Contributor Author

@alexdowad what I discovered is that up to 7.4 null for $charset gave Unknown encoding "". ac0da09 made both parameters nullable during 8.0-dev and 29b02bf dropped that again a month later. To the best of my understanding it never worked in a stable release, although the manual says "8.0.0: charset and transfer_encoding are nullable now". This PR makes null behave like an omitted argument again, as ac0da09 intended.

@alexdowad

Copy link
Copy Markdown
Contributor

@thunderer That is very good information, thanks.
What you are proposing seems to make sense, but it is a behavior change from the code we have had in place for the last 6 years, so I just want to be cautious about changing things again. I'll let you know when I've had some time to do my own investigation.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants