Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

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

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[String] Method toByteString conversion using iconv is unreachable
  • Loading branch information
Vincentv92 authored and nicolas-grekas committed Nov 9, 2023
commit 08a27c28ca5bd657892fbedffd49f6340df028d0
5 changes: 4 additions & 1 deletion 5 src/Symfony/Component/String/AbstractString.php
Original file line number Diff line number Diff line change
Expand Up @@ -577,8 +577,11 @@ public function toByteString(string $toEncoding = null): ByteString
try {
try {
$b->string = mb_convert_encoding($this->string, $toEncoding, 'UTF-8');
} catch (InvalidArgumentException $e) {
} catch (InvalidArgumentException|\ValueError $e) {
if (!\function_exists('iconv')) {
if ($e instanceof \ValueError) {
throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
}
throw $e;
Vincentv92 marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
18 changes: 18 additions & 0 deletions 18 src/Symfony/Component/String/Tests/AbstractAsciiTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -1583,4 +1583,22 @@ public static function provideWidth(): array
[17, "\u{007f}\u{007f}f\u{001b}[0moo\u{0001}bar\u{007f}cccïf\u{008e}cy\u{0005}1", false], // f[0moobarcccïfcy1
];
}

/**
* @dataProvider provideToByteString
*/
public function testToByteString(string $origin, string $encoding)
{
$instance = static::createFromString($origin)->toByteString($encoding);
$this->assertInstanceOf(ByteString::class, $instance);
}

public static function provideToByteString(): array
{
return [
['žsžsý', 'UTF-8'],
['žsžsý', 'windows-1250'],
['žsžsý', 'Windows-1252'],
];
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.