Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Controller::generateUrl() must be of the type string, null returned #30306

Copy link
Copy link
Closed
@AmsTaFFix

Description

@AmsTaFFix
Issue body actions

Symfony version(s) affected: 4.2.2

Description
method \Symfony\Bundle\FrameworkBundle\Controller\ControllerTrait::generateUrl has return value : string. This method delegates call to
\Symfony\Component\Routing\Generator\UrlGenerator::generate(), then to \Symfony\Component\Routing\Generator\UrlGenerator::doGenerate() and method doGenerate can return null on lines 170 and 224

How to reproduce
create route with regexp requirements and try to generate url with invalid data with \Symfony\Bundle\FrameworkBundle\Controller\ControllerTrait::generateUrl

Possible Solution

  • return empty string in \Symfony\Component\Routing\Generator\UrlGenerator::doGenerate()
  • typecast result of router::generate in ControllerTrait::generateUrl

Additional context
log message

{
    "level": "CRITICAL",
    "context_exception": {
      "files": [
        "/usr/local/www/citilink.ru_new/vendor/symfony/framework-bundle/Controller/ControllerTrait.php:78"
      ],
      "traces": [
        [
          "/usr/local/www/citilink.ru_new/App/Configurator/Controller/ItemController.php:333",
          "/usr/local/www/citilink.ru_new/vendor/symfony/http-kernel/HttpKernel.php:150",
          "/usr/local/www/citilink.ru_new/vendor/symfony/http-kernel/HttpKernel.php:67",
          "/usr/local/www/citilink.ru_new/vendor/symfony/http-kernel/Kernel.php:198",
          "/usr/local/www/citilink.ru_new/htdocs/app_prod.php:21"
        ]
      ],
      "messages": [
        "Return value of Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller::generateUrl() must be of the type string, null returned"
      ],
      "codes": [
        0
      ],
      "classes": [
        "Symfony\\Component\\Debug\\Exception\\FatalThrowableError"
      ]
    },
    "@timestamp": "2019-02-18T15:10:00.337Z",
    "input": {
      "type": "log"
    },
    "message": "Uncaught PHP Exception TypeError: \"Return value of Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller::generateUrl() must be of the type string, null returned\" at /usr/local/www/citilink.ru_new/vendor/symfony/framework-bundle/Controller/ControllerTrait.php line 78",
    "channel": "request"
    }
  }
}

code

    public function getActualConfigurationId(): Response
    {
        $session = $this->getSession();
        $user = $session->getUser();
        /** @var ConfigurationService $configurationService */
        $configurationService = $this->get('configurator.service.configuration.item');
        /** @var SimpleStorageInterface $guestUserConfigurationStorage */
        $guestUserConfigurationStorage = $this->get('configurator.service.guest_user_configuration_storage');

        $actualConfigurationId = $user !== null
            ? $configurationService->getActualConfigurationId($user, $session->getSpaceId())
            : $actualConfigurationId = $guestUserConfigurationStorage->get($session->getSessionId(), __METHOD__);

        $url = $actualConfigurationId
            ? $this->generateUrl(
                'configuratorInfo',
                ['itemId' => $actualConfigurationId],
                UrlGeneratorInterface::ABSOLUTE_URL
            )
            : null;

        return $this->ajaxSuccess(['id' => $actualConfigurationId, 'url' => $url]);
    }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.