[BUGFIX] Localization State does not properly sanitize and enrich
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / DataHandling / Localization / State.php
index 9c1026d..fce8365 100644 (file)
@@ -82,7 +82,7 @@ class State
     {
         return array_keys(
             array_filter(
-                $GLOBALS['TCA'][$tableName]['columns'],
+                $GLOBALS['TCA'][$tableName]['columns'] ?? [],
                 function (array $fieldConfiguration) {
                     return !empty(
                         $fieldConfiguration['config']
@@ -139,6 +139,15 @@ class State
     protected $originalStates;
 
     /**
+     * @var array
+     */
+    protected $validStates = [
+        self::STATE_CUSTOM,
+        self::STATE_SOURCE,
+        self::STATE_PARENT,
+    ];
+
+    /**
      * @param string $tableName
      * @param array $states
      */
@@ -148,8 +157,9 @@ class State
         $this->states = $states;
         $this->originalStates = $states;
 
-        $this->states = $this->sanitize($states);
-        $this->states = $this->enrich($states);
+        $this->states = $this->enrich(
+            $this->sanitize($states)
+        );
     }
 
     /**
@@ -311,7 +321,12 @@ class State
     protected function enrich(array $states)
     {
         foreach (static::getFieldNames($this->tableName) as $fieldName) {
-            if (!empty($states[$fieldName])) {
+            $isValid = in_array(
+                $states[$fieldName] ?? null,
+                $this->validStates,
+                true
+            );
+            if ($isValid) {
                 continue;
             }
             $states[$fieldName] = static::STATE_PARENT;