From e05968ae13375a091acd631fb8e5c1c2a1552883 Mon Sep 17 00:00:00 2001 From: Luke Downing Date: Tue, 15 Jun 2021 18:58:52 +0100 Subject: [PATCH] [8.x] Adds a small fix for unicode with blade echo handlers (#37697) * Adds a small fix for unicode with blade handlers. * CS fixes * CS fixes --- src/Illuminate/View/Compilers/Concerns/CompilesEchos.php | 8 +++++++- tests/View/Blade/BladeEchoHandlerTest.php | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/View/Compilers/Concerns/CompilesEchos.php b/src/Illuminate/View/Compilers/Concerns/CompilesEchos.php index a7073b79ca7f..c8ed7aa59b4e 100644 --- a/src/Illuminate/View/Compilers/Concerns/CompilesEchos.php +++ b/src/Illuminate/View/Compilers/Concerns/CompilesEchos.php @@ -141,7 +141,13 @@ protected function addBladeCompilerVariable($result) */ protected function wrapInEchoHandler($value) { - return empty($this->echoHandlers) ? $value : '$__bladeCompiler->applyEchoHandler('.Str::beforeLast($value, ';').')'; + $value = Str::of($value) + ->trim() + ->when(Str::endsWith($value, ';'), function ($str) { + return $str->beforeLast(';'); + }); + + return empty($this->echoHandlers) ? $value : '$__bladeCompiler->applyEchoHandler('.$value.')'; } /** diff --git a/tests/View/Blade/BladeEchoHandlerTest.php b/tests/View/Blade/BladeEchoHandlerTest.php index 38b54d0f5e08..20c97096a414 100644 --- a/tests/View/Blade/BladeEchoHandlerTest.php +++ b/tests/View/Blade/BladeEchoHandlerTest.php @@ -102,6 +102,7 @@ public function nonStringableDataProvider() ['{{"foo" . "bar"}}', 'foobar'], ['{{ 1 + 2 }}{{ "test"; }}', '3test'], ['@php($test = "hi"){{ $test }}', 'hi'], + ['{!! " " !!}', ' '], ]; } }