Feature #31777

SubRoutes should allow routes starting or ending with /

Added by Alexander Berl over 3 years ago. Updated over 2 years ago.

Status:Resolved Start date:2011-11-12
Priority:Should have Due date:
Assigned To:Bastian Waidelich % Done:

100%

Category:MVC - Routing
Target version:-
PHP Version: Complexity:
Has patch:No

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

duplicated by TYPO3.Flow - Bug #35096: Subroutes can't use empty uriPattern as fallback Closed 2012-03-21

Associated revisions

Revision 46904338
Added by Bastian Waidelich over 2 years ago

[FEATURE] Remove trailing slash from routes for empty subroutes

Flow throws an exception if a route contains a trailing slash in
order to avoid duplicate slashes in URIs and to make it possible
to add some kind of global default suffix to all URIs.
When using sub routes and a prefix with a trailing slash in the
uriPattern of the main route (e.g. uriPattern: 'blog/<BlogSubroutes>')
this leads to an unwanted exception if there is an empty (fallback)
subroute because the merged uriPattern would contain a trailing
slash ("blog/").

This change strips trailing slashes from merged uriPatterns if the sub
routes uriPattern is empty.

Change-Id: I3499600774d62780982e707c4a7eff738f52b703
Resolves: #31777
Releases: 1.2

History

#1 Updated by Bastian Waidelich over 3 years ago

  • Status changed from New to Accepted
  • Assigned To set to Bastian Waidelich

Good point and very nice description, thanks!
I'll look into this asap.

#2 Updated by Gerrit Code Review over 2 years ago

  • Status changed from Accepted to Under Review

Patch set 1 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/16671

#3 Updated by Gerrit Code Review over 2 years ago

Patch set 2 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/16671

#4 Updated by Bastian Waidelich over 2 years ago

Bastian Waidelich wrote:

I'll look into this asap.

as I wrote, as spät as possible ;) sorry for the delay

#5 Updated by Bastian Waidelich over 2 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100

Also available in: Atom PDF