Skip to content

Commit

Permalink
[TASK] Remove some PHP < 8.1 specific code switches
Browse files Browse the repository at this point in the history
Resolves: #96587
Releases: main
Change-Id: I2c44ce44a667f246c25eaab4c87cb57a3a21c6cb
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/73067
Tested-by: core-ci <typo3@b13.com>
Tested-by: Stefan Bürk <stefan@buerk.tech>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
  • Loading branch information
lolli42 authored and andreaskienast committed Jan 19, 2022
1 parent 9b6b4bc commit 4a5e6a1
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 68 deletions.
9 changes: 2 additions & 7 deletions typo3/sysext/core/Resources/PHP/ClassMapGenerator.php
Expand Up @@ -120,11 +120,6 @@ public static function createMap($path, $blacklist = null, IOInterface $io = nul
*/
private static function findClasses($path)
{
$extraTypes = PHP_VERSION_ID < 50400 ? '' : '|trait';
if (defined('HHVM_VERSION') && version_compare(HHVM_VERSION, '3.3', '>=')) {
$extraTypes .= '|enum';
}

try {
$contents = @php_strip_whitespace($path);
if (!$contents) {
Expand All @@ -140,7 +135,7 @@ private static function findClasses($path)
}

// return early if there is no chance of matching anything in this file
if (!preg_match('{\b(?:class|interface' . $extraTypes . ')\s}i', $contents)) {
if (!preg_match('{\b(?:class|interface|trait)\s}i', $contents)) {
return [];
}

Expand All @@ -165,7 +160,7 @@ private static function findClasses($path)

preg_match_all('{
(?:
\b(?<![\$:>])(?P<type>class|interface' . $extraTypes . ') \s++ (?P<name>[a-zA-Z_\x7f-\xff:][a-zA-Z0-9_\x7f-\xff:\-]*+)
\b(?<![\$:>])(?P<type>class|interface|trait) \s++ (?P<name>[a-zA-Z_\x7f-\xff:][a-zA-Z0-9_\x7f-\xff:\-]*+)
| \b(?<![\$:>])(?P<ns>namespace) (?P<nsname>\s++[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+(?:\s*+\\\\\s*+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+)*+)? \s*+ [\{;]
)
}ix', $contents, $matches);
Expand Down
Expand Up @@ -97,11 +97,7 @@ public function render(): string
$linkText = (string)$linkResult->getLinkText();
$attributes = $linkResult->getAttributes();
unset($attributes['href']);
if (PHP_VERSION_ID < 80100) {
$linkText = htmlspecialchars($linkText, ENT_COMPAT | ENT_SUBSTITUTE, 'utf-8', false);
} else {
$linkText = htmlspecialchars($linkText, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, 'utf-8', false);
}
$linkText = htmlspecialchars($linkText, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, 'utf-8', false);
}
}
$tagContent = $this->renderChildren();
Expand Down
Expand Up @@ -38,13 +38,7 @@ public function isRenderedDataProvider(): array
'fieldNamePrefix' => 'fieldNamePrefix<>&"\'',
],
// first element having "@extension" in name attribute
// check against correct value regarding php 8.1 change of default argument values of flags for ex. htmlspecialchars()
// @todo remove conditional values when php 8.1 is min requirement
(PHP_VERSION_ID < 80100
// before php 8.1 - remove this for >php8.1 only
? '<input type="hidden" name="fieldNamePrefix&lt;&gt;&amp;&quot;\'[__referrer][@extension]" value="" />'
// for php 8.1
: '<input type="hidden" name="fieldNamePrefix&lt;&gt;&amp;&quot;&#039;[__referrer][@extension]" value="" />'),
'<input type="hidden" name="fieldNamePrefix&lt;&gt;&amp;&quot;&#039;[__referrer][@extension]" value="" />',
],
'#2' => [
'{f:form(action:action, method:method, fieldNamePrefix:fieldNamePrefix)}',
Expand All @@ -54,13 +48,7 @@ public function isRenderedDataProvider(): array
'fieldNamePrefix' => 'fieldNamePrefix<>&"\'',
],
// first element having "@extension" in name attribute
// check against correct value regarding php 8.1 change of default argument values of flags for ex. htmlspecialchars()
// @todo remove conditional values when php 8.1 is min requirement
(PHP_VERSION_ID < 80100
// before php 8.1 - remove this for >php8.1 only
? '<input type="hidden" name="fieldNamePrefix&lt;&gt;&amp;&quot;\'[__referrer][@extension]" value="" />'
// for php 8.1
: '<input type="hidden" name="fieldNamePrefix&lt;&gt;&amp;&quot;&#039;[__referrer][@extension]" value="" />'),
'<input type="hidden" name="fieldNamePrefix&lt;&gt;&amp;&quot;&#039;[__referrer][@extension]" value="" />',
],
];
}
Expand Down
Expand Up @@ -64,24 +64,12 @@ public function renderEncodesEmailInFrontendDataProvider(): array
'Susceptible email' => [
'<f:link.email email="\"><script>alert(\'email\')</script>" />',
0,
// check against correct value regarding php 8.1 change of default argument values of flags for ex. htmlspecialchars()
// @todo remove conditional values when php 8.1 is min requirement
(PHP_VERSION_ID < 80100
// before php 8.1 - remove this for >php8.1 only
? '<a href="mailto:&quot;&gt;&lt;script&gt;alert(\'email\')&lt;/script&gt;">&quot;&gt;&lt;script&gt;alert(\'email\')&lt;/script&gt;</a>'
// for php 8.1
: '<a href="mailto:&quot;&gt;&lt;script&gt;alert(&#039;email&#039;)&lt;/script&gt;">&quot;&gt;&lt;script&gt;alert(&#039;email&#039;)&lt;/script&gt;</a>'),
'<a href="mailto:&quot;&gt;&lt;script&gt;alert(&#039;email&#039;)&lt;/script&gt;">&quot;&gt;&lt;script&gt;alert(&#039;email&#039;)&lt;/script&gt;</a>',
],
'Susceptible email with spam protection' => [
'<f:link.email email="\"><script>alert(\'email\')</script>" />',
1,
// check against correct value regarding php 8.1 change of default argument values of flags for ex. htmlspecialchars()
// @todo remove conditional values when php 8.1 is min requirement
(PHP_VERSION_ID < 80100
// before php 8.1 - remove this for >php8.1 only
? '<a href="#" data-mailto-token="nbjmup+&quot;&gt;&lt;tdsjqu&gt;bmfsu(\'fnbjm\')&lt;0tdsjqu&gt;" data-mailto-vector="1">&quot;&gt;&lt;script&gt;alert(\'email\')&lt;/script&gt;</a>'
// for php 8.1
: '<a href="#" data-mailto-token="nbjmup+&quot;&gt;&lt;tdsjqu&gt;bmfsu(&#039;fnbjm&#039;)&lt;0tdsjqu&gt;" data-mailto-vector="1">&quot;&gt;&lt;script&gt;alert(&#039;email&#039;)&lt;/script&gt;</a>'),
'<a href="#" data-mailto-token="nbjmup+&quot;&gt;&lt;tdsjqu&gt;bmfsu(&#039;fnbjm&#039;)&lt;0tdsjqu&gt;" data-mailto-vector="1">&quot;&gt;&lt;script&gt;alert(&#039;email&#039;)&lt;/script&gt;</a>',
],
];
}
Expand Down
Expand Up @@ -172,19 +172,10 @@ public function renderWithAssignedParametersDataProvider(): array
'data-other' => '\'\'',
],
],
// check against correct value regarding php 8.1 change of default argument values of flags for ex. htmlspecialchars()
// @todo remove conditional values when php 8.1 is min requirement
(PHP_VERSION_ID < 80100
// before php 8.1 - remove this for >php8.1 only
? '<a href="http://typo3.org/" title="&lt;Title&gt;" target="_self"'
. ' class="&lt;CSS&gt;" data-bs-html="&lt;div data-template=&quot;template&quot;&gt;'
. '&lt;img src=&quot;logo.png&quot; alt=&quot;&amp;quot;&amp;lt;ALT&amp;gt;&amp;quot;&quot;&gt;&lt;/div&gt;"'
. ' data-other="\'\'">Link Text</a>'
// for php 8.1
: '<a href="http://typo3.org/" title="&lt;Title&gt;" target="_self"'
. ' class="&lt;CSS&gt;" data-bs-html="&lt;div data-template=&quot;template&quot;&gt;'
. '&lt;img src=&quot;logo.png&quot; alt=&quot;&amp;quot;&amp;lt;ALT&amp;gt;&amp;quot;&quot;&gt;&lt;/div&gt;"'
. ' data-other="&#039;&#039;">Link Text</a>'),
'<a href="http://typo3.org/" title="&lt;Title&gt;" target="_self"'
. ' class="&lt;CSS&gt;" data-bs-html="&lt;div data-template=&quot;template&quot;&gt;'
. '&lt;img src=&quot;logo.png&quot; alt=&quot;&amp;quot;&amp;lt;ALT&amp;gt;&amp;quot;&quot;&gt;&lt;/div&gt;"'
. ' data-other="&#039;&#039;">Link Text</a>',
],
];
}
Expand Down
Expand Up @@ -17,7 +17,6 @@

namespace TYPO3\CMS\Impexp\Tests\Functional;

use Doctrine\DBAL\Platforms\SqlitePlatform;
use PHPUnit\Util\Xml\Loader as XmlLoader;
use TYPO3\CMS\Backend\Routing\Route;
use TYPO3\CMS\Core\Core\Bootstrap;
Expand Down Expand Up @@ -97,24 +96,11 @@ protected function isCaseSensitiveFilesystem(): bool

/**
* Asserts that two XML documents are equal.
*
* @todo: This is a hack to align 'expected' fixture files on sqlite: sqlite returns integer
* fields as string, so the exported xml miss the 'type="integer"' attribute.
* This change drops 'type="integer"' from the expectations if on sqlite.
* This needs to be changed in impexp, after that this helper method can vanish again.
* SQLite also now returns the correct type as of PHP 8.1, so the string mangling
* is no longer necessary.
*
* @todo: Remove this workaround method after minimum php version requirement is set to >8.1.
*/
public function assertXmlStringEqualsXmlFileWithIgnoredSqliteTypeInteger(string $expectedFile, string $actualXml): void
{
$actual = (new XmlLoader())->load($actualXml);
$expectedFileContent = file_get_contents($expectedFile);
$databasePlatform = $this->getConnectionPool()->getConnectionForTable('pages')->getDatabasePlatform();
if ((PHP_VERSION_ID < 80100) && $databasePlatform instanceof SqlitePlatform) {
$expectedFileContent = str_replace(' type="integer"', '', $expectedFileContent);
}
$expected = (new XmlLoader())->load($expectedFileContent);
self::assertEquals($expected, $actual);
}
Expand Down
2 changes: 1 addition & 1 deletion typo3/sysext/install/Classes/SystemEnvironment/Check.php
Expand Up @@ -850,6 +850,6 @@ protected function getBytesFromSizeMeasurement($measurement)

private function checkImageResource($imageResource): bool
{
return is_resource($imageResource) || (PHP_MAJOR_VERSION >= 8 && $imageResource instanceof \GdImage);
return $imageResource instanceof \GdImage;
}
}

0 comments on commit 4a5e6a1

Please sign in to comment.