Commit 020f22dc authored by Christian Eßl's avatar Christian Eßl Committed by Daniel Goerz
Browse files

[BUGFIX] Substitute form references for array keys as well in ext:form

In ext:form, string placeholders, like "{text-1}", can be used inside
the finisher to place form inputs, made by the user, inside fields like
the email subject, reploy to email and name, etc. These string
substitutions however were not done for array keys (only array values).

Resolves: #88550
Releases: master
Change-Id: I727850f3e15479215b56be4cd136d93644b0d435
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/61890


Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Susanne Moog's avatarSusanne Moog <look@susi.dev>
Tested-by: Daniel Goerz's avatarDaniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Susanne Moog's avatarSusanne Moog <look@susi.dev>
Reviewed-by: Daniel Goerz's avatarDaniel Goerz <daniel.goerz@posteo.de>
parent 84e50d22
......@@ -280,12 +280,13 @@ abstract class AbstractFinisher implements FinisherInterface
// resolve (recursively) all array items
if (is_array($needle)) {
return array_map(
function ($item) use ($formRuntime) {
return $this->substituteRuntimeReferences($item, $formRuntime);
},
$needle
);
$substitutedNeedle = [];
foreach ($needle as $key => $item) {
$key = $this->substituteRuntimeReferences($key, $formRuntime);
$item = $this->substituteRuntimeReferences($item, $formRuntime);
$substitutedNeedle[$key] = $item;
}
return $substitutedNeedle;
}
// substitute one(!) variable in string which either could result
......
......@@ -442,6 +442,44 @@ class AbstractFinisherTest extends UnitTestCase
self::assertEquals(1, preg_match($expected, (string)$mockAbstractFinisher->_call('substituteRuntimeReferences', $input, $formRuntimeProphecy->reveal())));
}
/**
* @test
*/
public function substituteRuntimeReferencesReturnsResolvesElementIdentiiersInArrayKeys(): void
{
$mockAbstractFinisher = $this->getAccessibleMockForAbstractClass(
AbstractFinisher::class,
[],
'',
false
);
$elementIdentifier1 = 'element-identifier-1';
$elementValue1 = 'norbert';
$elementIdentifier2 = 'element-identifier-2';
$elementValue2 = ['stan', 'steve'];
$input = [
'{' . $elementIdentifier1 . '}' => [
'lisa',
'{' . $elementIdentifier2 . '}',
],
];
$expected = [
'norbert' => [
'lisa',
['stan', 'steve'],
]
];
$formRuntimeProphecy = $this->createFormRuntimeProphecy([
$elementIdentifier1 => $elementValue1,
$elementIdentifier2 => $elementValue2
]);
$this->assertSame($expected, $mockAbstractFinisher->_call('substituteRuntimeReferences', $input, $formRuntimeProphecy->reveal()));
}
/**
* @test
*/
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment