Cannot use a / in route parameter

Created on 3 June 2016, over 9 years ago
Updated 30 January 2023, over 2 years ago

According to the Symfony documentation it should be possible to use a "/" (forward slash) in a route path by following the instructions here https://symfony.com/doc/3.4/routing/slash_in_parameter.html

_hello:
    path:     /hello/{username}
    defaults: { _controller: AppBundle:Demo:hello }
    requirements:
        username: .+

I've tried this but a request to /hello/foo/bar didn't call my controller.

🐛 Bug report
Status

Needs review

Version

10.1

Component
Routing 

Last updated 10 days ago

Created by

miiimooo Europe

Live updates comments and jobs are added and updated live.
  • needs profiling

    It may affect performance, and thus requires in-depth technical reviews and profiling.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇮🇳India Raviknair45

    The Above patches work only upto 62 url parts after that route will be empty as $ancestors from getCandidateOutlines is having bitwise shift left condition of $end = (1 << $number_parts) - 1; which will skip the execution at https://git.drupalcode.org/project/drupal/-/blob/10.1.x/core/lib/Drupal/Core/Routing/RouteProvider.php#L297

  • Status changed to Needs work over 2 years ago
  • 🇺🇸United States smustgrave

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

    This could use an issue summary update with proposed solution and remaining tasks. Think it would be a good spot for the profiling to happen also.

  • 🇬🇧United Kingdom joachim

    Updated the IS.

  • 🇫🇷France prudloff Lille

    prudloff changed the visibility of the branch 2741939-cannot-use-a to hidden.

  • 🇫🇷France prudloff Lille

    prudloff changed the visibility of the branch 2741939-9.2.x to hidden.

  • 🇫🇷France prudloff Lille

    prudloff changed the visibility of the branch 2741939-8.9.x to hidden.

  • 🇪🇸Spain isholgueras

    Core is currently doing for /system/files/ route.

    It uses an InboundPathProcessor to get the route of the file, set it to a query parameter and return just the /system/files to allow the route system to match the route, no matter how many / the file has, because now is in a query parameter.

    class PathProcessorFiles implements InboundPathProcessorInterface {
    
      /**
       * {@inheritdoc}
       */
      public function processInbound($path, Request $request) {
        if (str_starts_with($path, '/system/files/') && !$request->query->has('file')) {
          $file_path = preg_replace('|^\/system\/files\/|', '', $path);
          $request->query->set('file', $file_path);
          return '/system/files';
        }
        return $path;
      }
    
    }
    

    Then, in the controller, it gets the target by accessing the file query parameter.

        $target = $request->query->get('file');
    
Production build 0.71.5 2024