Bug #86557

routeEnhancers: Routing ending Slash is double

Added by Christian Knauf almost 2 years ago. Updated about 1 year ago.

Status:
Closed
Priority:
Must have
Assignee:
-
Category:
Link Handling, Site Handling & Routing
Target version:
-
Start date:
2018-10-03
Due date:
% Done:

100%

TYPO3 Version:
9
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:
On Location Sprint

Description

If you want to add a "/" at the end of a URL, it will be added twice to the URL in the frontend.

routeEnhancers:
Suffix:
type: PageType
default: /
index: ''
map:
.json: 10

Associated revisions

Revision a83df281 (diff)
Added by Ralf Merz over 1 year ago

[BUGFIX] Add also the "/" slash to ROUTE_PATH_DELIMITERS array

This is needed so that the PageType routeEnhancer is able to build URL
with a single trailing slash.
In other words, this fixes that a double trailing slash was created.

The functional test pageTypeDecoratorIsApplied gets extended with 2
instruction scenarios to set routeEnhancer PageTypeDecorator to
have a trailing slash instead of .html suffix tested, too.

Resolves: #86557
Releases: master, 9.5
Change-Id: If03bad8f054dc659f8870a98e064d9869597e8ba
Reviewed-on: https://review.typo3.org/59123
Reviewed-by: Michael Giek <>
Tested-by: Michael Giek <>
Tested-by: TYPO3com <>
Reviewed-by: Daniel Goerz <>
Reviewed-by: Benni Mack <>
Tested-by: Benni Mack <>

Revision 88e54f9f (diff)
Added by Ralf Merz over 1 year ago

[BUGFIX] Add also the "/" slash to ROUTE_PATH_DELIMITERS array

This is needed so that the PageType routeEnhancer is able to build URL
with a single trailing slash.
In other words, this fixes that a double trailing slash was created.

The functional test pageTypeDecoratorIsApplied gets extended with 2
instruction scenarios to set routeEnhancer PageTypeDecorator to
have a trailing slash instead of .html suffix tested, too.

Resolves: #86557
Releases: master, 9.5
Change-Id: If03bad8f054dc659f8870a98e064d9869597e8ba
Reviewed-on: https://review.typo3.org/59375
Tested-by: TYPO3com <>
Reviewed-by: Benni Mack <>
Tested-by: Benni Mack <>

History

#1 Updated by Christian Knauf almost 2 years ago

  • Assignee set to Oliver Hader

#2 Updated by Daniel Dorndorf almost 2 years ago

I also had the issue and solved this with a custom page type decorator.

For the trailing slash ROUTE_PATH_DELIMITERS should have / in the array
The class also solves the problem with the startpage generating "/index/" or "index.html" if you force ".html"

PageTypeSuffix:
  type: CustomPageType
  default: '/'
  index: 'index'
  map:
    '/': 0
class CustomPageTypeDecorator extends PageTypeDecorator
{
    public const IGNORE_INDEX = [
        '/index.html',
        '/index/',
    ];

    public const ROUTE_PATH_DELIMITERS = ['.', '-', '_', '/'];

    /**
     * @param \TYPO3\CMS\Core\Routing\RouteCollection $collection
     * @param array $parameters
     */
    public function decorateForGeneration(RouteCollection $collection, array $parameters): void
    {
        parent::decorateForGeneration($collection, $parameters);

        /**
         * @var string $routeName
         * @var \TYPO3\CMS\Core\Routing\Route $route
         */
        foreach ($collection->all() as $routeName => $route) {
            $path = $route->getPath();

            if (true === \in_array($path, self::IGNORE_INDEX, true)) {
                $route->setPath('/');
            }
        }
    }
}

#3 Updated by Wouter Wolters almost 2 years ago

  • Assignee deleted (Oliver Hader)

#4 Updated by Christian Knauf almost 2 years ago

  • Priority changed from Should have to Must have

#5 Updated by Matthias Krappitz almost 2 years ago

Can confirm this problem. No matter how you do it, you end up with trailing "//" instead of trailing "/". Tried the following variants:

routeEnhancers:
    PageType:
        type: PageType
        default: '/'
        map:
            '/': 1

routeEnhancers:
    Suffix:
        type: PageType
        default: '/'
        index: ''
        map:
            '/': 1

routeEnhancers:
    PageTypeSuffix:
        type: PageType
        default: '/'
        index: ''
        map:
            '/': 1

#6 Updated by Matthias Krappitz almost 2 years ago

Sven Wappler proposed a simple fix for this double trailing "/" issue to change line 150 of typo3/sysext/core/Classes/Routing/Enhancer/PageTypeDecorator.php from

if ($value !== '' && !in_array($value{0}, static::ROUTE_PATH_DELIMITERS)) {

to
if ($value !== '' && !in_array($value{0}, static::ROUTE_PATH_DELIMITERS) && $value !== '/') {

when the "/" suffix for the urls in the siteconf is as written above. This works for me!

#7 Updated by Susanne Moog over 1 year ago

  • Sprint Focus set to On Location Sprint

#8 Updated by Edward A. Gabdullin over 1 year ago

Matthias Krappitz wrote:

Sven Wappler proposed a simple fix for this double trailing "/" issue to change line 150 of typo3/sysext/core/Classes/Routing/Enhancer/PageTypeDecorator.php from
[...]
to
[...]
when the "/" suffix for the urls in the siteconf is as written above. This works for me!

After this change, XmlSitemap displays links without type=1533906435, for example it should be:

https://domain.name/en/?sitemap=pages&type=1533906435&cHash=a99c2cfce77a538c64e3de0213cf780e

but it turns out
https://domain.name/en/?sitemap=pages&cHash=a99c2cfce77a538c64e3de0213cf780e

P.S. Sorry, an error in the path XmlSitemap appears after adding the suffix:

routeEnhancers:
  PageTypeSuffix:
    type: PageType
    default: /
    index: ''
    map:
      /: 1

#9 Updated by Jesper Mathiasen over 1 year ago

Another inconsistency is with translations. As default the urls generated will not have a trailing slash:

domain.com/page/subpage

but the top level page for a translation will have a trailing slash:

domain.com/en/

Of course when using '.html' suffixes with the index property set to 'index' this does not pose a problem as it would then look like this:

domain.com/en/index.html

Is the forced trailing slash for a translated index page the desired outcome, i.e. does it have some semantic meaning?

The solution above (https://forge.typo3.org/issues/86557#note-2) solves it for me by creating consistent trailing slashes.

#10 Updated by Gerrit Code Review over 1 year ago

  • Status changed from New to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/59123

#11 Updated by Ralf Merz over 1 year ago

Hi,

i´ve just provided a patch with the added trailing slash to the constant as Daniel said in
https://forge.typo3.org/issues/86557#note-2

I use this in my config.yaml (rss and json may be ignored):

routeEnhancers:
  PageTypeSuffix:
    type: PageType
    default: '/'
    suffix: '/'
    index: 'index'
    map:
      'rss.feed': 13
      '.json': 26
      '/': 0

Would that help to get "trailing slash" on track?

#12 Updated by Gerrit Code Review over 1 year ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/59123

#13 Updated by Gerrit Code Review over 1 year ago

Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/59123

#14 Updated by Gerrit Code Review over 1 year ago

Patch set 4 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/59123

#15 Updated by Gerrit Code Review over 1 year ago

Patch set 1 for branch 9.5 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/59375

#16 Updated by Anonymous over 1 year ago

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

#17 Updated by Benni Mack about 1 year ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF