From 566acdb3d08746d36a4e4eaf33f67dfed51a684a Mon Sep 17 00:00:00 2001 From: Benni Mack <benni@typo3.org> Date: Wed, 30 May 2018 19:25:09 +0200 Subject: [PATCH] [TASK] Deprecate JavaScriptEncoder class The JavaScriptEncoder class was superseded with GeneralUtility::quoteJSvalue() in TYPO3 6.2 and is not used anymore. It is marked as deprecated. Resolves: #85120 Releases: master Change-Id: I13cb97e3ff6bb23d937a5193d392f92eb759ba9d Reviewed-on: https://review.typo3.org/57093 Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl> Tested-by: TYPO3com <no-reply@typo3.com> Tested-by: Wouter Wolters <typo3@wouterwolters.nl> Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> Tested-by: Christian Kuhn <lolli@schwarzbu.ch> --- .../Classes/Encoder/JavaScriptEncoder.php | 3 ++ .../Deprecation-85120-JavaScriptEncoder.rst | 35 +++++++++++++++++++ .../Encoder/JavaScriptEncoderTest.php | 2 +- .../ExtensionScanner/Php/ClassNameMatcher.php | 5 +++ 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Deprecation-85120-JavaScriptEncoder.rst rename typo3/sysext/core/Tests/{Unit => UnitDeprecated}/Encoder/JavaScriptEncoderTest.php (97%) diff --git a/typo3/sysext/core/Classes/Encoder/JavaScriptEncoder.php b/typo3/sysext/core/Classes/Encoder/JavaScriptEncoder.php index dacd7b9b69ba..4dd2b46449d9 100644 --- a/typo3/sysext/core/Classes/Encoder/JavaScriptEncoder.php +++ b/typo3/sysext/core/Classes/Encoder/JavaScriptEncoder.php @@ -22,6 +22,7 @@ namespace TYPO3\CMS\Core\Encoder; * It encodes all characters except alphanumericals and the immune characters to a hex representation. * @copyright 2009-2010 The OWASP Foundation * @link http://www.owasp.org/index.php/ESAPI + * @deprecated since TYPO3 v9.3, will be removed in TYPO3 v10.0 */ class JavaScriptEncoder implements \TYPO3\CMS\Core\SingletonInterface { @@ -51,9 +52,11 @@ class JavaScriptEncoder implements \TYPO3\CMS\Core\SingletonInterface * Populates the $hex map of non-alphanumeric single-byte characters. * * Alphanumerical character are set to NULL in the matrix. + * @deprecated since TYPO3 v9.3, will be removed in TYPO3 v10.0 */ public function __construct() { + trigger_error('TYPO3\'s JavaScriptEncoder will be removed in TYPO3 v10.0, use PHPs native json_encode() or GeneralUtility::quoteJSvalue() instead.', E_USER_DEPRECATED); $this->charsetConversion = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Charset\CharsetConverter::class); for ($i = 0; $i < 256; $i++) { if ($i >= ord('0') && $i <= ord('9') || $i >= ord('A') && $i <= ord('Z') || $i >= ord('a') && $i <= ord('z')) { diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-85120-JavaScriptEncoder.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-85120-JavaScriptEncoder.rst new file mode 100644 index 000000000000..ca259efb5042 --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-85120-JavaScriptEncoder.rst @@ -0,0 +1,35 @@ +.. include:: ../../Includes.txt + +======================================= +Deprecation: #85120 - JavaScriptEncoder +======================================= + +See :issue:`85120` + +Description +=========== + +The standalone utility class :php:`TYPO3\CMS\Core\Encoder\JavaScriptEncoder` has been superseded in TYPO3 6.2 +by PHP's native :php:`json_encode()` and :php:`GeneralUtility::quoteJSvalue()` which provide significantly +performance improvements. The utility class is thus marked for removal in TYPO3 v10.0. + + +Impact +====== + +Instantiating the class will trigger a deprecation message. + + +Affected Installations +====================== + +TYPO3 installations with custom extensions still using this PHP class. + + +Migration +========= + +Use :php:`GeneralUtility::quoteJSvalue()` or :php:`json_encode()` with proper options as second parameter to +escape a string for JavaScript output. + +.. index:: PHP-API, FullyScanned \ No newline at end of file diff --git a/typo3/sysext/core/Tests/Unit/Encoder/JavaScriptEncoderTest.php b/typo3/sysext/core/Tests/UnitDeprecated/Encoder/JavaScriptEncoderTest.php similarity index 97% rename from typo3/sysext/core/Tests/Unit/Encoder/JavaScriptEncoderTest.php rename to typo3/sysext/core/Tests/UnitDeprecated/Encoder/JavaScriptEncoderTest.php index c44b8a2bb689..d9d2a36a81b9 100644 --- a/typo3/sysext/core/Tests/Unit/Encoder/JavaScriptEncoderTest.php +++ b/typo3/sysext/core/Tests/UnitDeprecated/Encoder/JavaScriptEncoderTest.php @@ -1,5 +1,5 @@ <?php -namespace TYPO3\CMS\Core\Tests\Unit\Encoder; +namespace TYPO3\CMS\Core\Tests\UnitDeprecated\Encoder; /* * This file is part of the TYPO3 CMS project. diff --git a/typo3/sysext/install/Configuration/ExtensionScanner/Php/ClassNameMatcher.php b/typo3/sysext/install/Configuration/ExtensionScanner/Php/ClassNameMatcher.php index 691ff43080b7..68aa6265194a 100644 --- a/typo3/sysext/install/Configuration/ExtensionScanner/Php/ClassNameMatcher.php +++ b/typo3/sysext/install/Configuration/ExtensionScanner/Php/ClassNameMatcher.php @@ -679,4 +679,9 @@ return [ 'Deprecation-85102-PhpOptionsUtility.rst', ], ], + 'TYPO3\CMS\Core\Encoding\JavaScriptEncoder' => [ + 'restFiles' => [ + 'Deprecation-85120-JavaScriptEncoder.rst', + ], + ], ]; -- GitLab