Issue Bug Closed

#104440stripPathSitePrefix breaks file path

Franz Holzinger 07/19/24, 19:51 updated 04/18/25, 12:23

Description

The internal method PathUtility::stripPathSitePrefix breaks the formerly correct path to files.
This happens if the class ImageContentObject (IMAGE) is used to create an Image HTML out of an image file.
There is a second error when TYPO3 wrongly generates an image file with duplicate slashes. As a side effect of stripPathSitePrefix the duplicate slash is fixed. But when a Middleware call is used then there is no such duplicate slash bug. This leads to the result that the slash before fileadmin is removed for a Middleware and the HTML image source is:

src="fileadmin/myimage.png"

instead of

src="/fileadmin/myimage.png"

Therefore the image is not found by the browser with the new TYPO3 routing enhancer.

    /**
     * Strip first part of a path, equal to the length of public web path including trailing slash
     *
     * @internal
     */
    public static function stripPathSitePrefix(string $path): string
    {
        debug ($path, 'stripPathSitePrefix $path: demoshop12//fileadmin/ Doppelter falscher Slash');
        debug (Environment::getPublicPath(), 'stripPathSitePrefix Environment::getPublicPath()');
        $result = substr($path, strlen(Environment::getPublicPath() . '/'));
        debug ($result, 'stripPathSitePrefix $result /fileadmin mit Slash vorne');

        return $result;
    }

Reviews 2