Skip to content

[String] Method toByteString conversion using iconv is unreachable #52489

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

Closed
Tetragramat opened this issue Nov 7, 2023 · 0 comments · Fixed by #52491
Closed

[String] Method toByteString conversion using iconv is unreachable #52489

Tetragramat opened this issue Nov 7, 2023 · 0 comments · Fixed by #52491

Comments

@Tetragramat
Copy link
Contributor

Symfony version(s) affected

5.4.30

Description

Method \Symfony\Component\String\AbstractString::toByteString throws ValueError exception when unsupported encoding for mb_convert_encoding is passed instead of using fallback iconv.

How to reproduce

u('žsžsý')->toByteString('windows-1250');

Throws ValueError with message mb_convert_encoding(): Argument #2 ($to_encoding) must be a valid encoding, "windows-1250" given.

Instead of returning ByteString with output of iconv

Possible Solution

No response

Additional Context

iconv('UTF-8', 'windows-1250', 'žsžsý') returns expected value.

Using PHP 8.1

It is possible that nobody noticed that PHP 8.0 added ValueError exception https://www.php.net/manual/en/function.mb-convert-encoding so the code is not compatible with php >= 8.0

@Tetragramat Tetragramat added the Bug label Nov 7, 2023
nicolas-grekas added a commit that referenced this issue Nov 9, 2023
…eachable (Vincentv92)

This PR was squashed before being merged into the 5.4 branch.

Discussion
----------

[String] Method toByteString conversion using iconv is unreachable

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Issues        | Fix #52489 <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead -->
| License       | MIT

<!--
Replace this notice by a description of your feature/bugfix.
This will help reviewers and should be a good start for the documentation.

Additionally (see https://symfony.com/releases):
 - Always add tests and ensure they pass.
 - Bug fixes must be submitted against the lowest maintained branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too).
 - Features and deprecations must be submitted against the latest branch.
 - For new features, provide some code snippets to help understand usage.
 - Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry
 - Never break backward compatibility (see https://symfony.com/bc).
-->
Originating from original issue:
>It is possible that nobody noticed that PHP 8.0 added ValueError exception https://www.php.net/manual/en/function.mb-convert-encoding so the code is not compatible with php >= 8.0

That seems indeed to be the case

Commits
-------

08a27c2 [String] Method toByteString conversion using iconv is unreachable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants