From e52191fc7539f344051ef41076ae55ccbac13274 Mon Sep 17 00:00:00 2001
From: Benni Mack <benni@typo3.org>
Date: Mon, 18 Jan 2016 08:00:20 +0100
Subject: [PATCH] [!!!][TASK] Remove RTE transformation option preserveTables

The RTE transformation option "preserveTables" that
allows to keep HTML table elements and their contents
when not in transformation mode "ts_css" (but just in"ts")
is removed.

Use ts_css instead which keeps the tables as they are completely.

If the RTE should be configured to remove HTML tables
completely this can be done via denyTags := addToList(table).

Resolves: #72783
Releases: master
Change-Id: I008e809a51ce38938adfff64cadc2686d7304f9a
Reviewed-on: https://review.typo3.org/46041
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Reviewed-by: Mathias Schreiber <mathias.schreiber@wmdb.de>
Tested-by: Mathias Schreiber <mathias.schreiber@wmdb.de>
---
 typo3/sysext/core/Classes/Html/HtmlParser.php | 30 ++------------
 .../core/Classes/Html/RteHtmlParser.php       | 40 +------------------
 ...dRTETransformationOptionPreserveTables.rst | 32 +++++++++++++++
 3 files changed, 37 insertions(+), 65 deletions(-)
 create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Breaking-72783-RemovedRTETransformationOptionPreserveTables.rst

diff --git a/typo3/sysext/core/Classes/Html/HtmlParser.php b/typo3/sysext/core/Classes/Html/HtmlParser.php
index 3cf654b3065a..286af109133e 100644
--- a/typo3/sysext/core/Classes/Html/HtmlParser.php
+++ b/typo3/sysext/core/Classes/Html/HtmlParser.php
@@ -40,13 +40,13 @@ class HtmlParser
     /**
      * Returns an array with the $content divided by tag-blocks specified with the list of tags, $tag
      * Even numbers in the array are outside the blocks, Odd numbers are block-content.
-     * Use ->getAllParts() and ->removeFirstAndLastTag() to process the content if needed.
+     * Use ->removeFirstAndLastTag() to process the content if needed.
      *
      * @param string $tag List of tags, comma separated.
      * @param string $content HTML-content
      * @param bool $eliminateExtraEndTags If set, excessive end tags are ignored - you should probably set this in most cases.
      * @return array Even numbers in the array are outside the blocks, Odd numbers are block-content.
-     * @see splitTags(), getAllParts(), removeFirstAndLastTag()
+     * @see splitTags(), removeFirstAndLastTag()
      */
     public function splitIntoBlock($tag, $content, $eliminateExtraEndTags = false)
     {
@@ -147,12 +147,12 @@ class HtmlParser
     /**
      * Returns an array with the $content divided by tag-blocks specified with the list of tags, $tag
      * Even numbers in the array are outside the blocks, Odd numbers are block-content.
-     * Use ->getAllParts() and ->removeFirstAndLastTag() to process the content if needed.
+     * Use ->removeFirstAndLastTag() to process the content if needed.
      *
      * @param string $tag List of tags
      * @param string $content HTML-content
      * @return array Even numbers in the array are outside the blocks, Odd numbers are block-content.
-     * @see splitIntoBlock(), getAllParts(), removeFirstAndLastTag()
+     * @see splitIntoBlock(), removeFirstAndLastTag()
      */
     public function splitTags($tag, $content)
     {
@@ -182,28 +182,6 @@ class HtmlParser
         return $newParts;
     }
 
-    /**
-     * Returns an array with either tag or non-tag content of the result from ->splitIntoBlock()/->splitTags()
-     * Does not include the tags in the tag parts.
-     *
-     * @param array $parts Parts generated by ->splitIntoBlock() or >splitTags()
-     * @param bool $tag_parts Whether to return the tag-parts (default,TRUE) or what was outside the tags.
-     * @return array Tag-parts/Non-tag-parts depending on input argument settings
-     * @see splitIntoBlock(), splitTags()
-     * @private Currently only use to remove content from table cells inside RteHtmlParser
-     */
-    public function getAllParts($parts, $tag_parts = true)
-    {
-        $newParts = array();
-        foreach ($parts as $k => $v) {
-            if (($k + ($tag_parts ? 0 : 1)) % 2) {
-                $v = $this->removeFirstAndLastTag($v);
-                $newParts[] = $v;
-            }
-        }
-        return $newParts;
-    }
-
     /**
      * Removes the first and last tag in the string
      * Anything before the first and after the last tags respectively is also removed
diff --git a/typo3/sysext/core/Classes/Html/RteHtmlParser.php b/typo3/sysext/core/Classes/Html/RteHtmlParser.php
index bb27d18fbccf..6813e626389d 100644
--- a/typo3/sysext/core/Classes/Html/RteHtmlParser.php
+++ b/typo3/sysext/core/Classes/Html/RteHtmlParser.php
@@ -840,15 +840,8 @@ class RteHtmlParser extends \TYPO3\CMS\Core\Html\HtmlParser
                         break;
                     case 'ol':
                     case 'ul':
-                        if ($css) {
-                            $blockSplit[$k] = preg_replace(('/[' . LF . CR . ']+/'), ' ', $this->transformStyledATags($blockSplit[$k])) . $lastBR;
-                        }
-                        break;
                     case 'table':
-                        // Tables are NOT allowed in any form (unless preserveTables is set or CSS is the mode)
-                        if (!$this->procOptions['preserveTables'] && !$css) {
-                            $blockSplit[$k] = $this->TS_transform_db($this->removeTables($blockSplit[$k]));
-                        } else {
+                        if ($css) {
                             $blockSplit[$k] = preg_replace(('/[' . LF . CR . ']+/'), ' ', $this->transformStyledATags($blockSplit[$k])) . $lastBR;
                         }
                         break;
@@ -1321,37 +1314,6 @@ class RteHtmlParser extends \TYPO3\CMS\Core\Html\HtmlParser
         return GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
     }
 
-    /**
-     * Remove all tables from incoming code
-     * The function is trying to do this in a more or less respectful way. The approach is to resolve each table cells content and implode it all by <br /> chars. Thus at least the content is preserved in some way.
-     *
-     * @param string $value Input value
-     * @param string $breakChar Break character to use for linebreaks.
-     * @return string Output value
-     */
-    public function removeTables($value, $breakChar = '<br />')
-    {
-        // Splitting value into table blocks:
-        $tableSplit = $this->splitIntoBlock('table', $value);
-        // Traverse blocks of tables:
-        foreach ($tableSplit as $k => $v) {
-            if ($k % 2) {
-                $tableSplit[$k] = '';
-                $rowSplit = $this->splitIntoBlock('tr', $v);
-                foreach ($rowSplit as $k2 => $v2) {
-                    if ($k2 % 2) {
-                        $cellSplit = $this->getAllParts($this->splitIntoBlock('td', $v2));
-                        foreach ($cellSplit as $k3 => $v3) {
-                            $tableSplit[$k] .= $v3 . $breakChar;
-                        }
-                    }
-                }
-            }
-        }
-        // Implode it all again:
-        return implode($breakChar, $tableSplit);
-    }
-
     /**
      * Default tag mapping for TS
      *
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Breaking-72783-RemovedRTETransformationOptionPreserveTables.rst b/typo3/sysext/core/Documentation/Changelog/master/Breaking-72783-RemovedRTETransformationOptionPreserveTables.rst
new file mode 100644
index 000000000000..06ef996fc05d
--- /dev/null
+++ b/typo3/sysext/core/Documentation/Changelog/master/Breaking-72783-RemovedRTETransformationOptionPreserveTables.rst
@@ -0,0 +1,32 @@
+===================================================================
+Breaking: #72783 - Removed RTE transformation option preserveTables
+===================================================================
+
+Description
+===========
+
+The RTE transformation option "preserveTables" that allowed keeping HTML table tags and their contents is removed.
+
+Additionally, the methods ``RteHtmlParser->removeTables`` and ``HtmlParser->getAllParts`` are removed
+without substitution.
+
+
+Impact
+======
+
+When the RTE is configured to use ``overruleMode = ts`` instead of the default "ts_css" the option ``RTE.default.proc.preserveTables = 1`` will have no effect anymore.
+
+Calling ``RteHtmlParser->removeTables`` or ``HtmlParser->getAllParts`` inside a custom extension will result in a fatal PHP error.
+
+
+Affected Installations
+======================
+
+Any TYPO3 instance with a legacy-mode (overruleMode = ts) from TYPO3 3.x or an extension doing custom transformations by using ``RteHtmlParser->removeTables``.
+
+
+Migration
+=========
+
+Use the overruleMode ``ts_css`` instead which keeps the tables as they are. If tables should be disallowed inside the RTE
+the option ``RTE.default.proc.denyTags := addToList(table)`` can be used instead.
\ No newline at end of file
-- 
GitLab