[TASK] Deprecate JavaScriptEncoder class 93/57093/2
authorBenni Mack <benni@typo3.org>
Wed, 30 May 2018 17:25:09 +0000 (19:25 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Wed, 30 May 2018 17:49:07 +0000 (19:49 +0200)
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>
typo3/sysext/core/Classes/Encoder/JavaScriptEncoder.php
typo3/sysext/core/Documentation/Changelog/master/Deprecation-85120-JavaScriptEncoder.rst [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/Encoder/JavaScriptEncoderTest.php [deleted file]
typo3/sysext/core/Tests/UnitDeprecated/Encoder/JavaScriptEncoderTest.php [new file with mode: 0644]
typo3/sysext/install/Configuration/ExtensionScanner/Php/ClassNameMatcher.php

index dacd7b9..4dd2b46 100644 (file)
@@ -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 (file)
index 0000000..ca259ef
--- /dev/null
@@ -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/Unit/Encoder/JavaScriptEncoderTest.php
deleted file mode 100644 (file)
index c44b8a2..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-<?php
-namespace TYPO3\CMS\Core\Tests\Unit\Encoder;
-
-/*
- * This file is part of the TYPO3 CMS project.
- *
- * It is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License, either version 2
- * of the License, or any later version.
- *
- * For the full copyright and license information, please read the
- * LICENSE.txt file that was distributed with this source code.
- *
- * The TYPO3 project - inspiring people to share!
- */
-
-/**
- * Test cases for TYPO3\CMS\Core\Encoder\JavaScriptEncoder.
- */
-class JavaScriptEncoderTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
-{
-    /**
-     * @var \TYPO3\CMS\Core\Encoder\JavaScriptEncoder
-     */
-    protected $subject = null;
-
-    protected function setUp()
-    {
-        $this->subject = new \TYPO3\CMS\Core\Encoder\JavaScriptEncoder();
-    }
-
-    /**
-     * Data provider for encodeEncodesCorrectly.
-     *
-     * @return array
-     */
-    public function encodeEncodesCorrectlyDataProvider()
-    {
-        return [
-            'Immune characters are returned as is' => [
-                '._,',
-                '._,'
-            ],
-            'Alphanumerical characters are returned as is' => [
-                'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
-                'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
-            ],
-            'Angel brackets and ampersand are encoded' => [
-                '<>&',
-                '\\x3C\\x3E\\x26'
-            ],
-            'Quotes and slashes are encoded' => [
-                '"\'\\/',
-                '\\x22\\x27\\x5C\\x2F'
-            ],
-            'Empty string stays empty' => [
-                '',
-                ''
-            ],
-            'Exclamation mark and space are properly encoded' => [
-                'Hello World!',
-                'Hello\\x20World\\x21'
-            ],
-            'Whitespaces are properly encoded' => [
-                TAB . LF . CR . ' ',
-                '\\x09\\x0A\\x0D\\x20'
-            ],
-            'Null byte is properly encoded' => [
-                chr(0),
-                '\\x00'
-            ],
-            'Umlauts are properly encoded' => [
-                'ÜüÖöÄä',
-                '\\xDC\\xFC\\xD6\\xF6\\xC4\\xE4'
-            ]
-        ];
-    }
-
-    /**
-     * @test
-     * @param string $input
-     * @param string  $expected
-     * @dataProvider encodeEncodesCorrectlyDataProvider
-     */
-    public function encodeEncodesCorrectly($input, $expected)
-    {
-        $this->assertSame($expected, $this->subject->encode($input));
-    }
-}
diff --git a/typo3/sysext/core/Tests/UnitDeprecated/Encoder/JavaScriptEncoderTest.php b/typo3/sysext/core/Tests/UnitDeprecated/Encoder/JavaScriptEncoderTest.php
new file mode 100644 (file)
index 0000000..d9d2a36
--- /dev/null
@@ -0,0 +1,89 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\UnitDeprecated\Encoder;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+/**
+ * Test cases for TYPO3\CMS\Core\Encoder\JavaScriptEncoder.
+ */
+class JavaScriptEncoderTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
+{
+    /**
+     * @var \TYPO3\CMS\Core\Encoder\JavaScriptEncoder
+     */
+    protected $subject = null;
+
+    protected function setUp()
+    {
+        $this->subject = new \TYPO3\CMS\Core\Encoder\JavaScriptEncoder();
+    }
+
+    /**
+     * Data provider for encodeEncodesCorrectly.
+     *
+     * @return array
+     */
+    public function encodeEncodesCorrectlyDataProvider()
+    {
+        return [
+            'Immune characters are returned as is' => [
+                '._,',
+                '._,'
+            ],
+            'Alphanumerical characters are returned as is' => [
+                'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
+                'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
+            ],
+            'Angel brackets and ampersand are encoded' => [
+                '<>&',
+                '\\x3C\\x3E\\x26'
+            ],
+            'Quotes and slashes are encoded' => [
+                '"\'\\/',
+                '\\x22\\x27\\x5C\\x2F'
+            ],
+            'Empty string stays empty' => [
+                '',
+                ''
+            ],
+            'Exclamation mark and space are properly encoded' => [
+                'Hello World!',
+                'Hello\\x20World\\x21'
+            ],
+            'Whitespaces are properly encoded' => [
+                TAB . LF . CR . ' ',
+                '\\x09\\x0A\\x0D\\x20'
+            ],
+            'Null byte is properly encoded' => [
+                chr(0),
+                '\\x00'
+            ],
+            'Umlauts are properly encoded' => [
+                'ÜüÖöÄä',
+                '\\xDC\\xFC\\xD6\\xF6\\xC4\\xE4'
+            ]
+        ];
+    }
+
+    /**
+     * @test
+     * @param string $input
+     * @param string  $expected
+     * @dataProvider encodeEncodesCorrectlyDataProvider
+     */
+    public function encodeEncodesCorrectly($input, $expected)
+    {
+        $this->assertSame($expected, $this->subject->encode($input));
+    }
+}
index 691ff43..68aa626 100644 (file)
@@ -679,4 +679,9 @@ return [
             'Deprecation-85102-PhpOptionsUtility.rst',
         ],
     ],
+    'TYPO3\CMS\Core\Encoding\JavaScriptEncoder' => [
+        'restFiles' => [
+            'Deprecation-85120-JavaScriptEncoder.rst',
+        ],
+    ],
 ];