Commit b1f77997 authored by Benni Mack's avatar Benni Mack
Browse files

[TASK] Deprecate GeneralUtility::isAbsPath()

The replacement "PathUtility::isAbsolutePath()" works the same
way and has been around for a long time. For this reason
"GeneralUtility::isAbsPath()" is deprecated.

Resolves: #95367
Releases: master
Change-Id: Ia2b1bf71773d2f0d4c7ed0ab58a937652ddade74
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/71177

Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Wouter Wolters's avatarWouter Wolters <typo3@wouterwolters.nl>
Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Wouter Wolters's avatarWouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent 14840bf9
......@@ -15,6 +15,7 @@ declare(strict_types=1);
namespace TYPO3\CMS\Core\Html;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\PathUtility;
use TYPO3\HtmlSanitizer\Behavior;
use TYPO3\HtmlSanitizer\Builder\CommonBuilder;
use TYPO3\HtmlSanitizer\Sanitizer;
......@@ -35,7 +36,7 @@ class DefaultSanitizerBuilder extends CommonBuilder
$isOnCurrentHost = new Behavior\ClosureAttrValue(
static function (string $value): bool {
return GeneralUtility::isValidUrl($value) && GeneralUtility::isOnCurrentHost($value)
|| GeneralUtility::isAbsPath($value) && GeneralUtility::isAllowedAbsPath($value); // @todo incorrect abs path!
|| PathUtility::isAbsolutePath($value) && GeneralUtility::isAllowedAbsPath($value); // @todo incorrect abs path!
}
);
// + starting with `t3://`
......
......@@ -207,7 +207,7 @@ class FileWriter extends AbstractWriter
// skip mkdir if logFile refers to any scheme but vfs://, file:// or empty
$scheme = parse_url($this->logFile, PHP_URL_SCHEME);
if ($scheme === null || $scheme === 'file' || $scheme === 'vfs' || GeneralUtility::isAbsPath($this->logFile)) {
if ($scheme === null || $scheme === 'file' || $scheme === 'vfs' || PathUtility::isAbsolutePath($this->logFile)) {
// remove file:/ before creating the directory
$logFileDirectory = PathUtility::dirname((string)preg_replace('#^file:/#', '', $this->logFile));
if (!@is_dir($logFileDirectory)) {
......
......@@ -1756,7 +1756,7 @@ class GeneralUtility
}
$result = false;
// Make path absolute
if (!static::isAbsPath($path)) {
if (!PathUtility::isAbsolutePath($path)) {
$path = static::getFileAbsFileName($path);
}
if (static::isAllowedAbsPath($path)) {
......@@ -2823,7 +2823,7 @@ class GeneralUtility
if ((string)$extKey !== '' && ExtensionManagementUtility::isLoaded($extKey) && (string)$local !== '') {
$filename = ExtensionManagementUtility::extPath($extKey) . $local;
}
} elseif (!static::isAbsPath($filename)) {
} elseif (!PathUtility::isAbsolutePath($filename)) {
// is relative. Prepended with the public web folder
$filename = Environment::getPublicPath() . '/' . $filename;
} elseif (!(
......@@ -2862,9 +2862,11 @@ class GeneralUtility
*
* @param string $path File path to evaluate
* @return bool
* @deprecated will be removed in TYPO3 v12.0. Use PathUtility::isAbsolutePath() instead.
*/
public static function isAbsPath($path)
{
trigger_error('GeneralUtility::isAbsPath() will be removed in TYPO3 v12.0. Use PathUtility::isAbsolutePath() instead.', E_USER_DEPRECATED);
if (substr($path, 0, 6) === 'vfs://') {
return true;
}
......@@ -2886,7 +2888,7 @@ class GeneralUtility
return true;
}
$lockRootPath = $GLOBALS['TYPO3_CONF_VARS']['BE']['lockRootPath'] ?? '';
return static::isAbsPath($path) && static::validPathStr($path)
return PathUtility::isAbsolutePath($path) && static::validPathStr($path)
&& (
str_starts_with($path, Environment::getProjectPath())
|| str_starts_with($path, Environment::getPublicPath())
......@@ -2949,7 +2951,7 @@ class GeneralUtility
if (self::isOnCurrentHost($decodedUrl) && strpos($decodedUrl, self::getIndpEnv('TYPO3_SITE_URL')) === 0) {
$sanitizedUrl = $url;
}
} elseif (self::isAbsPath($decodedUrl) && self::isAllowedAbsPath($decodedUrl)) {
} elseif (PathUtility::isAbsolutePath($decodedUrl) && self::isAllowedAbsPath($decodedUrl)) {
$sanitizedUrl = $url;
} elseif (strpos($testAbsoluteUrl, self::getIndpEnv('TYPO3_SITE_PATH')) === 0 && $decodedUrl[0] === '/' &&
substr($decodedUrl, 0, 2) !== '//'
......
......@@ -269,8 +269,8 @@ class PathUtility
if (Environment::isWindows() && (substr($path, 1, 2) === ':/' || substr($path, 1, 2) === ':\\')) {
return true;
}
// Path starting with a / is always absolute, on every system
return substr($path, 0, 1) === '/';
// Path starting with a / is always absolute, on every system, VFS is needed for tests
return substr($path, 0, 1) === '/' || substr($path, 0, 6) === 'vfs://';
}
/**
......
.. include:: ../../Includes.txt
=================================================
Deprecation: #95367 - GeneralUtility::isAbsPath()
=================================================
See :issue:`95367`
Description
===========
The lowlevel TYPO3 API method :php:`GeneralUtility::isAbsPath()`
has been marked as deprecated.
Impact
======
Calling the method in your own PHP code will trigger a PHP deprecation
notice.
Affected Installations
======================
TYPO3 installations with custom extensions calling this PHP
method. You can check if you are affected via the Extension
Scanner tool provided in the Install Tool.
Migration
=========
Replace any calls to :php:`GeneralUtility::isAbsPath()` with
the exact equivalent :php:`PathUtility::isAbsolutePath()` which
checks for the same input.
.. index:: PHP-API, FullyScanned, ext:core
\ No newline at end of file
......@@ -24,17 +24,6 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
*/
class GeneralUtilityFilesystemFixture extends GeneralUtility
{
/**
* For testing we must allow vfs:// as first part of file path
*
* @param string $path File path to evaluate
* @return bool
*/
public static function isAbsPath($path): bool
{
return str_starts_with($path, 'vfs://') || parent::isAbsPath($path);
}
/**
* For testing we must allow vfs:// as first part file path
*
......
......@@ -845,7 +845,7 @@ class Indexer
$ext = $altExtension ?: strtolower($fI['extension']);
// Create abs-path:
if (!$contentTmpFile) {
if (!GeneralUtility::isAbsPath($file)) {
if (!PathUtility::isAbsolutePath($file)) {
// Relative, prepend public web path:
$absFile = GeneralUtility::getFileAbsFileName(Environment::getPublicPath() . '/' . $file);
} else {
......
......@@ -1254,4 +1254,11 @@ return [
'Deprecation-95326-VariousGetInstanceStaticMethodsOnSingletonInterfaces.rst',
],
],
'TYPO3\CMS\Core\Utility\GeneralUtility::isAbsPath' => [
'numberOfMandatoryArguments' => 1,
'maximumNumberOfArguments' => 1,
'restFiles' => [
'Deprecation-95367-GeneralUtilityisAbsPath.rst',
],
],
];
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment