diff --git a/typo3/sysext/core/Classes/Routing/Enhancer/VariableProcessor.php b/typo3/sysext/core/Classes/Routing/Enhancer/VariableProcessor.php index 308f4541a4e11bced978c7ae278c49f231601eec..9cf3a94f8bf30e39e8cd26d3b1082a17cfd7b165 100644 --- a/typo3/sysext/core/Classes/Routing/Enhancer/VariableProcessor.php +++ b/typo3/sysext/core/Classes/Routing/Enhancer/VariableProcessor.php @@ -280,6 +280,7 @@ class VariableProcessor return $values; } $namespacePrefix = $namespace ? $namespace . static::LEVEL_DELIMITER : ''; + $arguments = array_map('strval', $arguments); return array_map( function (string $value) use ($arguments, $namespacePrefix, $hash) { $value = $arguments[$value] ?? $value; @@ -308,6 +309,7 @@ class VariableProcessor if (empty($values) || empty($arguments) && empty($namespace)) { return $values; } + $arguments = array_map('strval', $arguments); $namespacePrefix = $namespace ? $namespace . static::LEVEL_DELIMITER : ''; return array_map( function (string $value) use ($arguments, $namespacePrefix, $hash) { @@ -318,7 +320,7 @@ class VariableProcessor $value = substr($value, strlen($namespacePrefix)); } $value = $this->resolveNestedValue($value); - $index = array_search($value, $arguments); + $index = array_search($value, $arguments, true); return $index !== false ? $index : $value; }, $values @@ -342,7 +344,7 @@ class VariableProcessor $result = []; foreach ($array as $key => $value) { if (is_array($value)) { - $result = array_merge( + $result = array_replace( $result, $this->deflateArray( $value, @@ -369,8 +371,8 @@ class VariableProcessor { $result = []; foreach ($array as $key => $value) { - $inflatedKey = $this->resolveHash($key); - // inflate nested values `namespace__any__neste` -> `namespace__any/nested` + $inflatedKey = $this->resolveHash((string)$key); + // inflate nested values `namespace__any__nested` -> `namespace__any/nested` $inflatedKey = $this->inflateNestedValue($inflatedKey, $namespace, $arguments); $steps = explode(static::LEVEL_DELIMITER, $inflatedKey); $pointer = &$result; @@ -395,9 +397,10 @@ class VariableProcessor if (!empty($namespace) && strpos($value, $namespacePrefix) !== 0) { return $value; } + $arguments = array_map('strval', $arguments); $possibleNestedValueKey = substr($value, strlen($namespacePrefix)); $possibleNestedValue = $this->nestedValues[$possibleNestedValueKey] ?? null; - if (!$possibleNestedValue || !in_array($possibleNestedValue, $arguments, true)) { + if ($possibleNestedValue === null || !in_array($possibleNestedValue, $arguments, true)) { return $value; } return $namespacePrefix . $possibleNestedValue; diff --git a/typo3/sysext/core/Tests/Unit/Routing/Enhancer/VariableProcessorTest.php b/typo3/sysext/core/Tests/Unit/Routing/Enhancer/VariableProcessorTest.php index 34ca8ed366d5f6dc7c0cf181beb186d3244a8b25..139ceceec2d10cb7a8425016b6fcb7dc4618860b 100644 --- a/typo3/sysext/core/Tests/Unit/Routing/Enhancer/VariableProcessorTest.php +++ b/typo3/sysext/core/Tests/Unit/Routing/Enhancer/VariableProcessorTest.php @@ -56,6 +56,12 @@ class VariableProcessorTest extends UnitTestCase $enforcedInflatedRoutePath, '/static/{!aa}/{bb}/{some_cc}/tail' ], + 'aa -> 1, no namespace (plain)' => [ + null, + ['aa' => 1], + $plainInflatedRoutePath, + '/static/{1}/{bb}/{some_cc}/tail' + ], 'aa -> zz, no namespace (plain)' => [ null, ['aa' => 'zz'], @@ -166,6 +172,10 @@ class VariableProcessorTest extends UnitTestCase ['a' => 'newA'], ['newA' => 'a', 'first__aa' => 'aa', 'first__second__aaa' => 'aaa', 'a9d66412d169b85537e11d9e49b75f9' => '@any'] ], + 'no namespace, a -> 1' => [ + ['a' => 1], + [1 => 'a', 'first__aa' => 'aa', 'first__second__aaa' => 'aaa', 'a9d66412d169b85537e11d9e49b75f9' => '@any'] + ], 'no namespace, a -> @any/nested' => [ ['a' => '@any/nested'], ['qbeced67e6b340abc67a397f6e90bb0' => 'a', 'first__aa' => 'aa', 'first__second__aaa' => 'aaa', 'a9d66412d169b85537e11d9e49b75f9' => '@any'] @@ -205,6 +215,11 @@ class VariableProcessorTest extends UnitTestCase [], ['a' => 'a', 'first' => ['aa' => 'aa', 'second' => ['aaa' => 'aaa', '@any' => '@any']]] ], + 'no namespace, a -> 1' => [ + '', + ['a' => 1], + ['a' => 'a', 'first' => ['aa' => 'aa', 'second' => ['aaa' => 'aaa', '@any' => '@any']]] + ], 'no namespace, a -> newA' => [ '', ['a' => 'newA'], @@ -286,6 +301,11 @@ class VariableProcessorTest extends UnitTestCase [], ['a' => 'a', 'b' => 'b', 'c' => ['d' => 'd', 'e' => 'e']] ], + 'a -> 1, no namespace' => [ + null, + ['a' => 1], + [1 => 'a', 'b' => 'b', 'c' => ['d' => 'd', 'e' => 'e']] + ], 'a -> newA, no namespace' => [ null, ['a' => 'newA'],