From 812ef5522a34293318899415755aeff814a16077 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Rish=C3=B8j?= Date: Mon, 1 May 2023 17:52:24 +0200 Subject: [PATCH] follow default PHP behavior and replace invalid codepoints (#46914) --- src/Illuminate/Support/helpers.php | 2 +- tests/Support/SupportHelpersTest.php | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Support/helpers.php b/src/Illuminate/Support/helpers.php index 5b3847f4a54f..e428824ae65b 100755 --- a/src/Illuminate/Support/helpers.php +++ b/src/Illuminate/Support/helpers.php @@ -120,7 +120,7 @@ function e($value, $doubleEncode = true) $value = $value->value; } - return htmlspecialchars($value ?? '', ENT_QUOTES, 'UTF-8', $doubleEncode); + return htmlspecialchars($value ?? '', ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8', $doubleEncode); } } diff --git a/tests/Support/SupportHelpersTest.php b/tests/Support/SupportHelpersTest.php index 1dec3cd9ad0e..aa1dda34cd74 100755 --- a/tests/Support/SupportHelpersTest.php +++ b/tests/Support/SupportHelpersTest.php @@ -37,6 +37,12 @@ public function testE() $this->assertEquals($str, e($html)); } + public function testEWithInvalidCodePoints() + { + $str = mb_convert_encoding('føø bar', 'ISO-8859-1', 'UTF-8'); + $this->assertEquals('f�� bar', e($str)); + } + /** * @requires PHP >= 8.1 */