From 08a27c28ca5bd657892fbedffd49f6340df028d0 Mon Sep 17 00:00:00 2001 From: Vincent Vermeulen Date: Tue, 7 Nov 2023 23:34:54 +0100 Subject: [PATCH] [String] Method toByteString conversion using iconv is unreachable --- .../Component/String/AbstractString.php | 5 ++++- .../String/Tests/AbstractAsciiTestCase.php | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/String/AbstractString.php b/src/Symfony/Component/String/AbstractString.php index 13567c7b0f4f..a0a801e69ab0 100644 --- a/src/Symfony/Component/String/AbstractString.php +++ b/src/Symfony/Component/String/AbstractString.php @@ -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; } diff --git a/src/Symfony/Component/String/Tests/AbstractAsciiTestCase.php b/src/Symfony/Component/String/Tests/AbstractAsciiTestCase.php index d25fbdee57b6..5d3127329c45 100644 --- a/src/Symfony/Component/String/Tests/AbstractAsciiTestCase.php +++ b/src/Symfony/Component/String/Tests/AbstractAsciiTestCase.php @@ -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'], + ]; + } } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy