-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
file_exists(): File name is longer than the maximum allowed path length on this platform (4096) #41745
Comments
src/Illuminate/View/Component.php /**
* Resolve the Blade view or view file that should be used when rendering the component.
*
* @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\Support\Htmlable|\Closure|string
*/
public function resolveView()
{
$view = $this->render();
if ($view instanceof ViewContract) {
return $view;
}
if ($view instanceof Htmlable) {
return $view;
}
$resolver = function ($view) {
$factory = Container::getInstance()->make('view');
return $factory->exists($view)
? $view
: $this->createBladeViewFromString($factory, $view);
};
return $view instanceof Closure ? function (array $data = []) use ($view, $resolver) {
return $resolver($view($data));
}
: $resolver($view);
} I think the problem is here. return $factory->exists($view)
? $view
: $this->createBladeViewFromString($factory, $view); Using |
Could you try to run the test, please? use Illuminate\Support\Facades\Blade;
public function test_rendering_long_blade_string() {
$longString = str_repeat('a', 4097);
$this->assertSame($longString . 'Taylor', Blade::render($longString .'{{ $name }}', ['name' => 'Taylor']));
} Passes for me. |
I tried to run the test and the test passed. |
This sounds like your FPM PHP configuration is different to the one which your PHPUnit tests are configured to run as. Are you running your PHPUnit tests against a locally installed PHP which is different from PHP-FPM? |
/**
* Resolve the Blade view or view file that should be used when rendering the component.
*
* @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\Support\Htmlable|\Closure|string
*/
public function resolveView()
{
$view = $this->render();
if ($view instanceof ViewContract) {
return $view;
}
if ($view instanceof Htmlable) {
return $view;
}
$resolver = function ($view) {
$factory = Container::getInstance()->make('view');
return $factory->exists($view)
? $view
: $this->createBladeViewFromString($factory, $view);
};
return $view instanceof Closure ? function (array $data = []) use ($view, $resolver) {
return $resolver($view($data));
}
: $resolver($view);
} I think this piece of code is problematic. |
Please paste the entire contents of |
$mailTemplateHtml = str_repeat('a', 4097);
Blade::render($mailTemplateHtml .'{{ $name }}', ['name' => 'Taylor']); |
Works fine for me: Please try a support channel: |
As before, check for differences between the |
Me personally consider @fangmuke's claim reasonable, the string variable purpose is not defined explicitly - why it may be content and a path? But at least we need a confirmation this approach breaks somehow, a failed test case. |
I compared |
I can't give you failed test cases. |
I'm running into this same issue and I'm able to reproduce the problem in Apache(using mod_php) and CLI. Laravel 9.5.1
<?php
namespace Tests\Unit;
use Blade;
use PHPUnit\Framework\TestCase;
class ExampleTest extends TestCase
{
public function test_rendering_long_blade_string() {
$longString = str_repeat('a', 4097);
$this->assertSame($longString . 'Taylor', Blade::render($longString .'{{ $name }}', ['name' => 'Taylor']));
}
} It fails for me.
If I try putting the following two lines in any controller, it also throws an exception. $mailTemplateHtml = str_repeat('a', 4097);
echo Blade::render($mailTemplateHtml .'{{ $name }}', ['name' => 'Taylor']); Here's the stacktrace
|
@driesvints, would you consider re-opening this issue now that there's a failed test case? There does seem to be a problem here, and I haven't been able to identify any reasonable workaround. My personal feeling is that |
@m0n1ker could you also tell more about your environment? OS and |
Sure, this is a pretty vanilla CentOS 7 machine, running in VirtualBox, and provisioned by Vagrant. It's using the Official CentOS 7 box. It has PHP 8.0 installed from the Remi repository, along with Apache 2.4.53. The web root is Here's the output from |
Duplicate of #32254 |
PHP has a hard limit on path length as defined by the constant PHP also knows you are trying to check plain file existence and calls https://github.com/php/php-src/blob/master/ext/standard/filestat.c#L757 If you have no https://github.com/php/php-src/blob/master/main/fopen_wrappers.c#L282 It has no warnings, just returns false, like in my case. If you set I suppose your environment overrides Although it's OK according to PHP design, I would say we have to add the PHP_MAXLENGTH value check in the Blade string code. |
I will deliver a PR resolving these issues soon. |
* [9.x] Fix PHP warnings when rendering long blade string (#41745) * Apply fixes from StyleCI
* [9.x] Fix PHP warnings when rendering long blade string (laravel#41745) * Apply fixes from StyleCI (cherry picked from commit bb0da4a)
) * [9.x] Fix PHP warnings when rendering long blade string (#41745) * Apply fixes from StyleCI (cherry picked from commit bb0da4a) Co-authored-by: Andrew Bashtannik <[email protected]>
Hi there, I have encountered this issue on long Blade content in database. Laravel 10 running on Debian 12, limit is 4096. When reaching the View/Component:174, the following code is too lazy:
This breaks once the code reaches file_exists, as the application path + ".blade.php" is added to the filepath tested, thus getting "File name is longer than the maximum allowed". Adding the app path + ".blade.php" would be the right test for strlen. I have patched my own code with a call to str_pad when I'm close to PHP_MAXPATHLEN, based on the length of my application path. Would love to simply force Blade::render to use a Blade string and not test any filepath. |
Description:
Calling
Blade::render($mailTemplateHtml)
can't run normally in thePHP-FPM
ofUbuntu
.Steps To Reproduce:
It must be under
Ubuntu
.The text was updated successfully, but these errors were encountered: