Feature #31777

SubRoutes should allow routes starting or ending with /

Added by Alexander Berl over 9 years ago. Updated over 8 years ago.

Status:
Resolved
Priority:
Should have
Category:
MVC - Routing
Target version:
-
Start date:
2011-11-12
Due date:
% Done:

100%

Estimated time:
PHP Version:
Has patch:
No
Complexity:

Description

Following scenario:

I have a new FLOW3 application and want to include another application with a special route prefix. I choose the Blog example for simplicity leading to the following Routing setup in my global Routes.yaml:

-
  name: 'Blog'
  uriPattern: 'blog/<BlogSubroutes>'
  defaults:
    '@package':    'TYPO3.Blog'
    '@format':     'html'
  subRoutes:
    BlogSubroutes:
      package: TYPO3.Blog

This causes a FLOW3 Exception when calling the uri /blog with the message:

The URI pattern "blog/" of route "Blog :: Fallback rule" ends with a slash, which is not allowed. You can put the trailing slash in brackets to make it optional.

However, putting the slash into round brackets isn't a solution, since multiple optional route parts aren't allowed, which cannot be prevented when including external applications, and when calling /blog I end up at /blogadmin/setup which is obviously not the intended Fallback route way, nor the correct path.
"flow3 routing:list" doesn't complain about this route btw.

The solution would be to remove the slash from the uriPattern and edit the TYPO3.Blog Routes.yaml to have all non-Fallback routes start with a slash.
However, then the Blog could not be inserted as the main Route, i.e. uriPattern: '<BlogSubroutes>', without editing the Routes.yaml file again, to avoid the Exception that Routes may not start with a slash.

Feature Request:
Hence I suggest to change the behaviour to allow SubRoutes to end with a slash, if not generally, then at least for the case that the subroute is empty (i.e. the Fallback case).

The line of code in question is TYPO3\FLOW3\MVC\Web\Routing\Route:542 as of FLOW3 1.0

if (substr($this->uriPattern, -1) === '/') {
    throw new \TYPO3\FLOW3\MVC\Exception\InvalidUriPatternException('The URI pattern "' . $this->uriPattern . '" of route "' . $this->getName() . 
        '" ends with a slash, which is not allowed. You can put the trailing slash in brackets to make it optional.', 1234782997);
}

Since the routes are merged by the ConfigurationManager beforehand it's not easy to check if the current subroutes' uriPattern is empty at this location. This would either require keeping the subroute parts in the Route object, or the easy solution would be to just remove these lines and possibly replace them with
$this->uriPattern = rtrim($this->uriPattern, '/');

which I'm not sure about the consequences yet.


Related issues

Has duplicate TYPO3.Flow - Bug #35096: Subroutes can't use empty uriPattern as fallbackClosedBastian Waidelich2012-03-21

Actions

Also available in: Atom PDF