From 13daa035698e31b3dc240b8af784c99f4ceaaa51 Mon Sep 17 00:00:00 2001 From: Roberto Guido Date: Mon, 8 Aug 2022 15:29:28 +0200 Subject: [PATCH] Improved check on long Blade strings --- src/Illuminate/View/Component.php | 2 +- src/Illuminate/View/FileViewFinder.php | 3 ++- tests/Integration/View/BladeTest.php | 23 +++++++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/View/Component.php b/src/Illuminate/View/Component.php index 0acee35ca066..7dd14a65e266 100644 --- a/src/Illuminate/View/Component.php +++ b/src/Illuminate/View/Component.php @@ -74,7 +74,7 @@ public function resolveView() $resolver = function ($view) { $factory = Container::getInstance()->make('view'); - return strlen($view) <= PHP_MAXPATHLEN && $factory->exists($view) + return $factory->exists($view) ? $view : $this->createBladeViewFromString($factory, $view); }; diff --git a/src/Illuminate/View/FileViewFinder.php b/src/Illuminate/View/FileViewFinder.php index 5502fe5ae870..93b9a814e44a 100755 --- a/src/Illuminate/View/FileViewFinder.php +++ b/src/Illuminate/View/FileViewFinder.php @@ -128,7 +128,8 @@ protected function findInPaths($name, $paths) { foreach ((array) $paths as $path) { foreach ($this->getPossibleViewFiles($name) as $file) { - if ($this->files->exists($viewPath = $path.'/'.$file)) { + $viewPath = $path.'/'.$file; + if (strlen($viewPath) <= PHP_MAXPATHLEN && $this->files->exists($viewPath)) { return $viewPath; } } diff --git a/tests/Integration/View/BladeTest.php b/tests/Integration/View/BladeTest.php index b3d8f51eedc7..e48969181aab 100644 --- a/tests/Integration/View/BladeTest.php +++ b/tests/Integration/View/BladeTest.php @@ -4,6 +4,7 @@ use Illuminate\Support\Facades\Blade; use Illuminate\Support\Facades\View; +use Illuminate\Support\Str; use Illuminate\View\Component; use Orchestra\Testbench\TestCase; @@ -30,6 +31,13 @@ public function test_rendering_blade_component_instance() $this->assertSame('Hello Taylor', Blade::renderComponent($component)); } + public function test_rendering_large_blade_component_instance() + { + $component = new LargeComponent(); + + $this->assertSame($component->contents, Blade::renderComponent($component)); + } + public function test_basic_blade_rendering() { $view = View::make('hello', ['name' => 'Taylor'])->render(); @@ -142,3 +150,18 @@ public function render() return 'Hello {{ $name }}'; } } + +class LargeComponent extends Component +{ + public $contents; + + public function __construct() + { + $this->contents = Str::random(PHP_MAXPATHLEN); + } + + public function render() + { + return $this->contents; + } +}