Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Fix PHP_MAXPATHLEN check for existing check of files for views #50962

Merged
merged 3 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Illuminate/View/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ protected function extractBladeViewFromString($contents)
return static::$bladeViewCache[$key];
}

if (strlen($contents) <= PHP_MAXPATHLEN && $this->factory()->exists($contents)) {
if ($this->factory()->exists($contents)) {
return static::$bladeViewCache[$key] = $contents;
}

Expand Down
4 changes: 3 additions & 1 deletion src/Illuminate/View/FileViewFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ 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;
}
}
Expand Down
24 changes: 24 additions & 0 deletions tests/Integration/View/BladeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Support\Facades\View;
use Illuminate\View\Component;
use Orchestra\Testbench\TestCase;
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;

Expand All @@ -26,6 +27,29 @@ public function test_rendering_blade_long_maxpathlen_string()
$this->assertSame($longString.'a', $result);
}

#[RunInSeparateProcess]
public function test_rendering_blade_long_maxpathlen_string_with_exact_length()
{
// The PHP_MAXPATHLEN restriction is only active, if
// open_basedir is set and active. Otherwise, the check
// for the PHP_MAXPATHLEN is not active.
if (ini_get('open_basedir') === '') {
$openBaseDir = windows_os() ? explode('\\', __DIR__)[0].'\\'.';'.sys_get_temp_dir() : '/';
$iniSet = ini_set(
'open_basedir',
$openBaseDir
);

$this->assertNotFalse($iniSet, 'Could not set config for open_basedir.');
}

$longString = str_repeat('x', PHP_MAXPATHLEN);

$result = Blade::render($longString);

$this->assertSame($longString, $result);
}

public function test_rendering_blade_component_instance()
{
$component = new HelloComponent('Taylor');
Expand Down