Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[HttpKernel] TypeError in FileLinkFormatter for empty xdebug.file_link_format #45272

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

Closed
mttsch opened this issue Feb 1, 2022 · 0 comments
Closed

Comments

@mttsch
Copy link
Contributor

mttsch commented Feb 1, 2022

Symfony version(s) affected

6.0

Description

With this change in 6.0, the previously untyped FileLinkFormatter::$fileLinkFormat property now does not support strings anymore. As the default value of the constructor parameter $fileLinkFormat is null and FileLinkFormatter::FORMATS does not have an entry for null, after this line

$fileLinkFormat = (self::FORMATS[$fileLinkFormat] ?? $fileLinkFormat) ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');

$fileLinkFormat will be an empty string if xdebug.file_link_format is empty, which appears to be its default value. Thus,

if ($fileLinkFormat && !\is_array($fileLinkFormat)) {
$i = strpos($f = $fileLinkFormat, '&', max(strrpos($f, '%f'), strrpos($f, '%l'))) ?: \strlen($f);
$fileLinkFormat = [substr($f, 0, $i)] + preg_split('/&([^>]++)>/', substr($f, $i), -1, \PREG_SPLIT_DELIM_CAPTURE);
}

is never entered and

$this->fileLinkFormat = $fileLinkFormat;

throws a TypeError because a string is assigned to an array|false variable.

How to reproduce

  1. Setup PHP with an empty xdebug.file_link_format value:
$ php -i | grep xdebug.file_link_format
xdebug.file_link_format => no value => no value
  1. Install symfony with webapp (as instructed in the documentation):
composer create-project symfony/skeleton . 6.0.99 && composer require webapp

(I added the explicit version number because I was also testing previous versions where the issue did not occur.)

  1. You get the following exception:
!!  TypeError {#4981
!!    #message: "Cannot assign string to property Symfony\Component\HttpKernel\Debug\FileLinkFormatter::$fileLinkFormat of type array|false"
!!    #code: 0
!!    #file: "./vendor/symfony/http-kernel/Debug/FileLinkFormatter.php"
!!    #line: 53
!!    trace: {
!!      ./vendor/symfony/http-kernel/Debug/FileLinkFormatter.php:53 { …}
!!      ./var/cache/dev/ContainerQqKtafO/App_KernelDevDebugContainer.php:1236 {
!!        ContainerQqKtafO\App_KernelDevDebugContainer->getDebug_FileLinkFormatterService()
!!        ›         return ($this->privates['debug.file_link_formatter.url_format'] ?? $this->load('getDebug_FileLinkFormatter_UrlFormatService'));
!!        ›     });
!!        › }
!!      }
!!      ./var/cache/dev/ContainerQqKtafO/getVarDumper_ContextualizedCliDumper_InnerService.php:22 { …}
!!      ./var/cache/dev/ContainerQqKtafO/App_KernelDevDebugContainer.php:429 { …}
!!      ./var/cache/dev/ContainerQqKtafO/getDebug_DumpListenerService.php:23 { …}
!!      ./var/cache/dev/ContainerQqKtafO/App_KernelDevDebugContainer.php:429 { …}
!!      ./var/cache/dev/ContainerQqKtafO/App_KernelDevDebugContainer.php:825 { …}
!!      ./vendor/symfony/event-dispatcher/EventDispatcher.php:245 { …}
!!      ./vendor/symfony/event-dispatcher/EventDispatcher.php:76 { …}
!!      ./vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php:283 { …}
!!      ./vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php:146 { …}
!!      ./vendor/symfony/console/Application.php:1004 { …}
!!      ./vendor/symfony/framework-bundle/Console/Application.php:94 { …}
!!      ./vendor/symfony/console/Application.php:299 { …}
!!      ./vendor/symfony/framework-bundle/Console/Application.php:80 { …}
!!      ./vendor/symfony/console/Application.php:171 { …}
!!      ./vendor/symfony/runtime/Runner/Symfony/ConsoleApplicationRunner.php:54 { …}
!!      ./vendor/autoload_runtime.php:29 { …}
!!      ./bin/console:11 { …}
!!    }
!!  }

Possible Solution

Properly handle the case of $fileLinkFormat being an empty string by setting FileLinkFormatter::$fileLinkFormat to false.

Additional Context

No response

@mttsch mttsch added the Bug label Feb 1, 2022
fabpot added a commit that referenced this issue Feb 4, 2022
…link_format (fancyweb)

This PR was merged into the 6.0 branch.

Discussion
----------

[HttpKernel] Fix FileLinkFormatter with empty xdebug.file_link_format

| Q             | A
| ------------- | ---
| Branch?       | 6.0
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | #45272
| License       | MIT
| Doc PR        | -

`get_cfg_var('xdebug.file_link_format')` can return `'0'` or `''` and `$fileLinkFormat` will remain a string.

Alternative: we could add `|string` to the `$fileLinkFormat` property, it's already the case in some other parts of the code, but for this class at least I find it better to not add another type.

Commits
-------

1c60a5a [HttpKernel] Fix FileLinkFormatter with empty xdebug.file_link_format
@fabpot fabpot closed this as completed Feb 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants