Bug #90959

Wrong URL applied for Route

Added by Stefan Froemken 10 months ago. Updated 9 months ago.

Status:
New
Priority:
Should have
Assignee:
-
Category:
Link Handling, Site Handling & Routing
Start date:
2020-04-06
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
9
PHP Version:
7.2
Tags:
Complexity:
Is Regression:
Yes
Sprint Focus:

Description

Hello Core-Team,

a customer has following routeEnhancer configuration. I have adopted it to my local machine:

base: 'http://typo395.ddev.site/'
baseVariants: {  }
errorHandling: {  }
languages:
  -
    title: English
    enabled: true
    languageId: '0'
    base: /
    typo3Language: default
    locale: en_US.UTF-8
    iso-639-1: en
    navigationTitle: English
    hreflang: en-US
    direction: ltr
    flag: en-us-gb
  -
    title: German
    enabled: true
    languageId: '1'
    base: /de/
    typo3Language: de
    locale: de_DE.UTF-8
    iso-639-1: de
    navigationTitle: Deutsch
    hreflang: de-DE
    direction: ltr
    fallbackType: fallback
    fallbacks: '0'
    flag: de
    solr_core_read: ''
rootPageId: 1
routeEnhancers:
  News:
    type: Extbase
    extension: News
    plugin: Pi1
    routes:
      -
        routePath: '/page-{page}'
        _controller: 'News::list'
        _arguments:
          page: '@widget_0/currentPage'
      -
        routePath: '/{news-title}'
        _controller: 'News::detail'
        _arguments:
          news-title: news
      -
        routePath: '/{category-name}'
        _controller: 'News::list'
        _arguments:
          category-name: overwriteDemand/categories
      -
        routePath: '/{tag-name}'
        _controller: 'News::list'
        _arguments:
          tag-name: overwriteDemand/tags
    defaultController: 'News::list'
    defaults:
      page: '0'
    aspects:
      news-title:
        type: PersistedAliasMapper
        tableName: tx_news_domain_model_news
        routeFieldName: path_segment
      page:
        type: StaticRangeMapper
        start: '1'
        end: '100'
      category-name:
        type: PersistedAliasMapper
        tableName: sys_category
        routeFieldName: slug
      tag-name:
        type: PersistedAliasMapper
        tableName: tx_news_domain_model_tag
        routeFieldName: slug
  DateMenu:
    type: Extbase
    extension: News
    plugin: Pi1
    routes:
      -
        routePath: '/page-{page}'
        _controller: 'News::list'
        _arguments:
          page: '@widget_0/currentPage'
        requirements:
          page: \d+
      -
        routePath: '/{news-title}'
        _controller: 'News::detail'
        _arguments:
          news-title: news
      -
        routePath: '/{date-year}'
        _controller: 'News::list'
        _arguments:
          date-year: overwriteDemand/year
        requirements:
          date-year: \d+
      -
        routePath: '/{date-year}/page-{page}'
        _controller: 'News::list'
        _arguments:
          date-year: overwriteDemand/year
          page: '@widget_0/currentPage'
        requirements:
          date-year: \d+
          page: \d+
      -
        routePath: '/{date-year}/{date-month}'
        _controller: 'News::list'
        _arguments:
          date-month: overwriteDemand/month
          date-year: overwriteDemand/year
        requirements:
          date-month: \d+
          date-year: \d+
      -
        routePath: '/{date-year}/{date-month}/page-{page}'
        _controller: 'News::list'
        _arguments:
          date-month: overwriteDemand/month
          date-year: overwriteDemand/year
          page: '@widget_0/currentPage'
        requirements:
          date-month: \d+
          date-year: \d+
          page: \d+
    defaultController: 'News::list'
    defaults:
      page: '0'
      date-month: ''
      date-year: ''
    aspects:
      news-title:
        type: PersistedAliasMapper
        tableName: tx_news_domain_model_news
        routeFieldName: path_segment
      page:
        type: StaticRangeMapper
        start: '1'
        end: '25'
      date-month:
        type: StaticValueMapper
        map:
          '01': '01'
          '02': '02'
          '03': '03'
          '04': '04'
          '05': '05'
          '06': '06'
          '07': '07'
          '08': '08'
          '09': '09'
          10: '10'
          11: '11'
          12: '12'
      date-year:
        type: StaticRangeMapper
        start: '2000'
        end: '2030'

When customer opens list view of news following error occurs:

Parameter "acec1fc0ac7e1adfbcd522115dc0792" for route "tx_news_pi1_4" must match "[^/]++" ("" given) to generate a corresponding URL.

It has nothing to do with one or more slashes in path_segment, as there are no slashes in there.
Please have a look at the Routes name "tx_news_pi1_4". The last part of it is a counter of found Routes. As it starts with 0, five valid routes have been found with the configuration above. A little bit too much IMO. This has something to do with the configured "defaults" named page, date-month and date-year. These defaults will be added to all Routes regardless, if Routepath has these variables or not.
There is not check anymore, if configured route matches the requested URI. You only check, if configured Variable is Part of the MergedParameters regardless, if URI matches "/page-{page}/" or "news/{title}/{page}". Both Routes will be added because they contain {page}.

In our customers case the first processed route is " /{date-year}/{date-month}/page-{page}" although only a page ID is given. The other path parts are configured as empty in defaults. That's why path is now "///page-2" which is IMO very wrong, but explains the error we get.

In ExtbasePluginEnhancer in method getVariant I see, that you don't set any Requirements to new Route:

$route = new Route(rtrim($defaultPageRoute->getPath(), '/') . '/' . ltrim($routePath, '/'), $defaults, [], $options);

Can you please tell me why?

#1

Updated by Benni Mack 9 months ago

  • Target version changed from next-patchlevel to Candidate for patchlevel

Also available in: Atom PDF