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

Commit 08a27c2

Browse filesBrowse files
Vincentv92nicolas-grekas
authored andcommitted
[String] Method toByteString conversion using iconv is unreachable
1 parent 2cd1e97 commit 08a27c2
Copy full SHA for 08a27c2

File tree

Expand file treeCollapse file tree

2 files changed

+22
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+22
-1
lines changed

‎src/Symfony/Component/String/AbstractString.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/String/AbstractString.php
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,11 @@ public function toByteString(string $toEncoding = null): ByteString
577577
try {
578578
try {
579579
$b->string = mb_convert_encoding($this->string, $toEncoding, 'UTF-8');
580-
} catch (InvalidArgumentException $e) {
580+
} catch (InvalidArgumentException|\ValueError $e) {
581581
if (!\function_exists('iconv')) {
582+
if ($e instanceof \ValueError) {
583+
throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
584+
}
582585
throw $e;
583586
}
584587

‎src/Symfony/Component/String/Tests/AbstractAsciiTestCase.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/String/Tests/AbstractAsciiTestCase.php
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,4 +1583,22 @@ public static function provideWidth(): array
15831583
[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
15841584
];
15851585
}
1586+
1587+
/**
1588+
* @dataProvider provideToByteString
1589+
*/
1590+
public function testToByteString(string $origin, string $encoding)
1591+
{
1592+
$instance = static::createFromString($origin)->toByteString($encoding);
1593+
$this->assertInstanceOf(ByteString::class, $instance);
1594+
}
1595+
1596+
public static function provideToByteString(): array
1597+
{
1598+
return [
1599+
['žsžsý', 'UTF-8'],
1600+
['žsžsý', 'windows-1250'],
1601+
['žsžsý', 'Windows-1252'],
1602+
];
1603+
}
15861604
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.