Project

General

Profile

Actions

Bug #94537

closed

Page could not be resolved if page slug ending in index and using PageSuffix RouteEnhancer to add .php suffix to all pages of a site.

Added by Stefan Bürk almost 3 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Link Handling, Site Handling & Routing
Target version:
-
Start date:
2021-07-11
Due date:
% Done:

100%

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

Description

There is a weired behaviour (bug?) in resolving a page, if a PageSuffix RouteEnhancer is used to add .php to all
pages for typeNum 0.

I could reproduce this on a new Install with v9 and v10 (see below), 11.2 failed because of error in installer, and master not tried yet.
But i have checked the code in the Master, the code-block which generates this behaviour/bug is still (nearly) the same, and so should behave
the same way. (Eventually someone with master running can confirm this).

I debugged the TYPO3\CMS\Frontend\MiddlewarePageResolver

$pageArguments = $site->getRouter()->matchRequest($request, $previousResult);

or better to say the matchRequest() method from the TYPO3\CMS\Core\Routing\PageRouter

if (!empty($urlPath)) {
    $normalizedParams = $request->getAttribute('normalizedParams');
    if ($normalizedParams instanceof NormalizedParams) {
        $scriptName = ltrim($normalizedParams->getScriptName(), '/');
        if ($scriptName !== '' && strpos($urlPath, $scriptName) !== false) {
            $urlPath = str_replace($scriptName, '', $urlPath);
        }
    }
}

Here, the scriptName ( /index.php ) would be replaced with '', which will convert the called uri

/features-index.php to /features-

which generates a uri/id/slug is not the wanted page (given is a page with a set slug to /features-index). And as long as no page with the slug (/features-) exists (which should not be because of the tailing -), it throughs and page not found error (404).

I would call this a bug - or was this done intentionally ??

Can someone reproduce this and can we talk if this need some fixing ? It only occurs in the combination with the ".php" PageSuffix.

Calling '/features-index' will resolve the page just fine.

So, doing the replace in this manner:

if (!empty($urlPath)) {
    $normalizedParams = $request->getAttribute('normalizedParams');
    if ($normalizedParams instanceof NormalizedParams) {
        $scriptName = ltrim($normalizedParams->getScriptName(), '/');
        if ($scriptName !== '' && strpos($urlPath, $scriptName) !== false) {
            $urlPath = str_replace('/'.$scriptName, '', $urlPath);
        }
    }
}

It works in my case (real project) and the test installations done to verify this behaviour/issue.

So, can someone who is into this give his opinion ? How to fix it ?

If this is intentionally, then there should be some hints for editors and so on or something like this.

v9
--

- Created new project using composer and the introduction package
- Create new Siteconfig for Rootpage
- add PageSuffix RouteEnhancer to generated site-config:

routeEnhancers:
  PageTypeSuffix:
    type: PageType
    default: .php
    index: index
    map: {  }

- change in the page settings the slug for the feature page (PID: 81) to '/features-index' (save & close )
- click the "view" button on the page header
=> in a new tab http(s)://projectdomain/features-index.php is calles

error: Page Not Found (404)

v10
---

- Created new project using composer and the introduction package
- add PageSuffix RouteEnhancer to generated site-config:

routeEnhancers:
  PageTypeSuffix:
    type: PageType
    default: .php
    index: index
    map: {  }

- change in the page settings the slug for the feature page (PID: 80) to '/features-index' (save & close )
- click the "view" button on the page header
=> in a new tab http(s)://projectdomain/features-index.php is calles
> error: Page Not Found (404)

v11.2
-----

Could not get in running because of error in the install tool for createing admin user
- ajay request: Fatal error: Class TYPO3\CMS\Core\Http\SelfEmittableLazyOpenStream may not inherit from final class (GuzzleHttp\Psr7\LazyOpenStream) in /var/www/work/typo3-play/t3v11/public/typo3/sysext/core/Classes/Http/SelfEmittableLazyOpenStream.php on line 29,

v11 master
----------

not tried yet


Related issues 2 (0 open2 closed)

Related to TYPO3 Core - Bug #94905: FE requests to /index.php are broken without providing id get parameter, if no pageTypeSuffix routeEnhancer is configuredClosedStefan Bürk2021-08-16

Actions
Related to TYPO3 Core - Task #94968: Revert #94537 due to incompatibilities with certain server setupsClosedBenni Mack2021-08-23

Actions
Actions #1

Updated by Stefan Bürk almost 3 years ago

Bug/Behaviour verified for: v9,v10,master

=> Findings/notes

Found corresponding functional test: typo3/sysext/frontend/Tests/Functional/SiteHandling/EnhancerSiteRequest/PageTypeDecoratorTest.php

Added testcase(s) [extending DataProvider) for test pageTypeDecoratorIndexCanBePartOfSlug, because for this case there was no corresponding test (only with index and .html suffix)

What was shocking first, these tests passed successfully, even if manual testing in a real install/instance it breaks / displays 404 page not found.

As for now, these new tests MUST fail, but they don't.

I debugged / digged deeper in, and one of the differences is, that the normalizedParamsAttributes are not filled correctly in the functional tests compared to a real frontend request.
As so, scriptName is an empty string "", and as such, no replacement in functional tests. In an apache instance it would be "/index.php" because of the htacces rewriting, ltrimmed to index.php
which is simple str_replaced().

The testframework calls the middlewars, but the NormalizedParams Middleware does not add something (because things in the ServerRequest regarding serverParams are fully empty.

        $urlPath = $previousResult->getTail();
        // Remove the script name (e.g. index.php), if given
        if (!empty($urlPath)) {
            $normalizedParams = $request->getAttribute('normalizedParams');
            if ($normalizedParams instanceof NormalizedParams) {
                $scriptName = ltrim($normalizedParams->getScriptName(), '/');
                if ($scriptName !== '' && strpos($urlPath, $scriptName) !== false) {
                    $urlPath = str_replace($scriptName, '', $urlPath);
                }
            }
        }

So i digged deeper ... and in the testingframework there is the TYPO3\TestingFramework\Core\Functional->retrieveFrontendSubRequestResult method.
Here some values are written to $_SERVER array, but when the new ServerRequest is instanciated, it is not passed, which leads to the empty normalizedParams.
Passing the full $_SERVER array as serverParams argument for the constructur will faile a lot of tests. But using the folling subarray sets, runs all tests normally, and my new tow tests are failing as expected.

$serverRequest = new ServerRequest(
    $uri,
    $request->getMethod(),
    'php://input',
    $request->getHeaders()
    ,[
        'SCRIPT_NAME'   => $_SERVER['SCRIPT_NAME'],
        'HTTP_HOST'     => $_SERVER['HTTP_HOST'],
        'SERVER_NAME'   => $_SERVER['SERVER_NAME'],
    ]
);

Applying my noted workaround/fix for the TYPO3\CMS\Core\Routing\PageRouter->matchRequest() will pass the new tests successfully.

if (!empty($urlPath)) {
    $normalizedParams = $request->getAttribute('normalizedParams');
    if ($normalizedParams instanceof NormalizedParams) {
        $scriptName = ltrim($normalizedParams->getScriptName(), '/');
        if ($scriptName !== '' && strpos($urlPath, $scriptName) !== false) {
            $urlPath = str_replace('/'.$scriptName, '', $urlPath);
        }
    }
}

Note

Created a pull request for the testing framework, see: https://github.com/TYPO3/testing-framework/pull/244

Today Testingframework pullrequest was merged, tagged with new version and raised in master.

Actions #2

Updated by Gerrit Code Review almost 3 years 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/c/Packages/TYPO3.CMS/+/69854

Actions #3

Updated by Gerrit Code Review almost 3 years 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/c/Packages/TYPO3.CMS/+/69854

Actions #4

Updated by Stefan Bürk almost 3 years ago

Added a patch as WIP for now: https://review.typo3.org/c/Packages/TYPO3.CMS/+/69854

Until testingframework has improved, the functional test is useless (before & after), because it does not
initalize the frontend subrequest correctly in such way, that normalizedArguments holds /index.php as
scriptName like it would be in a real webrequest.

As such, the broken replacement which this patch tries to fix can only seen as broken before the patch,
if testingframework bugfix is in place and wired to the core.

See https://github.com/TYPO3/testing-framework/pull/244

Actions #5

Updated by Gerrit Code Review almost 3 years 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/c/Packages/TYPO3.CMS/+/69854

Actions #6

Updated by Gerrit Code Review almost 3 years 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/c/Packages/TYPO3.CMS/+/69854

Actions #7

Updated by Gerrit Code Review almost 3 years ago

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

Actions #8

Updated by Gerrit Code Review almost 3 years ago

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

Actions #9

Updated by Gerrit Code Review almost 3 years ago

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

Actions #10

Updated by Gerrit Code Review over 2 years ago

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

Actions #11

Updated by Gerrit Code Review over 2 years ago

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

Actions #12

Updated by Stefan Bürk over 2 years ago

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

Updated by Gerrit Code Review over 2 years ago

  • Status changed from Resolved to Under Review

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/c/Packages/TYPO3.CMS/+/70554

Actions #14

Updated by Stefan Bürk over 2 years ago

  • Status changed from Under Review to Resolved
Actions #15

Updated by Simon Gilli over 2 years ago

  • Related to Bug #94905: FE requests to /index.php are broken without providing id get parameter, if no pageTypeSuffix routeEnhancer is configured added
Actions #16

Updated by Benni Mack over 2 years ago

  • Related to Task #94968: Revert #94537 due to incompatibilities with certain server setups added
Actions #17

Updated by Benni Mack over 2 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF