Skip to content

Commit

Permalink
[BUGFIX] Allow CSV in startingPoints config as advertised
Browse files Browse the repository at this point in the history
The category starting points introduced with #95037 were designed to
allow comma-separated values in its configuration. Due to improper
tests, this specific notation was not discovered as being broken right
now.

If the incoming configuration is a string, GeneralUtility::intExplode()
is applied to remove any non-integer value. Afterwards, a new CSV
string is generated.

Resolves: #96397
Related: #95037
Releases: main, 11.5
Change-Id: I0759d8093bb4665b7709f4e20539307467f246df
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/72775
Tested-by: core-ci <typo3@b13.com>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
  • Loading branch information
andreaskienast committed Dec 21, 2021
1 parent 92072aa commit f1b4f90
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
Expand Up @@ -968,14 +968,19 @@ protected function parseStartingPointsFromSiteConfiguration(array $result, array
$parsedSiteConfiguration = $this->parseSiteConfiguration($result['site'], $fieldConfig['config']['treeConfig']['startingPoints']);
if ($parsedSiteConfiguration !== []) {
// $this->quoteParsedSiteConfiguration() is omitted on purpose, all values are cast to integers
$parsedSiteConfiguration = array_unique(array_map(static function ($value) {
$parsedSiteConfiguration = array_unique(array_map(static function ($value): string {
if (is_array($value)) {
return implode(',', array_map('intval', $value));
}

return (int)$value;
return implode(',', GeneralUtility::intExplode(',', $value, true));
}, $parsedSiteConfiguration));
$fieldConfig['config']['treeConfig']['startingPoints'] = $this->replaceParsedSiteConfiguration($fieldConfig['config']['treeConfig']['startingPoints'], $parsedSiteConfiguration);
$resolvedStartingPoins = $this->replaceParsedSiteConfiguration($fieldConfig['config']['treeConfig']['startingPoints'], $parsedSiteConfiguration);
// Add the resolved starting points while removing empty values
$fieldConfig['config']['treeConfig']['startingPoints'] = implode(
',',
GeneralUtility::trimExplode(',', $resolvedStartingPoins, true)
);
}

return $fieldConfig;
Expand Down
Expand Up @@ -191,16 +191,31 @@ public function addDataOverridesDefaultFieldConfigurationBySiteConfigDataProvide
'expectedStartingPoints' => '42,4711,12',
'site' => new Site('some-site', 1, ['rootPageId' => 1, 'categories' => ['contentCategory' => 4711]]),
],
'one setting, multiple categories' => [
'one setting, multiple categories as array' => [
'inputStartingPoints' => '###SITE:categories.contentCategories###',
'expectedStartingPoints' => '4711,4712,42',
'site' => new Site('some-site', 1, ['rootPageId' => 1, 'categories' => ['contentCategories' => [4711, 4712, 42]]]),
],
'one setting, multiple categories as csv' => [
'inputStartingPoints' => '###SITE:categories.contentCategories###',
'expectedStartingPoints' => '4711,4712,42',
'site' => new Site('some-site', 1, ['rootPageId' => 1, 'categories' => ['contentCategories' => '4711,4712,42']]),
],
'two settings' => [
'inputStartingPoints' => '42,###SITE:categories.contentCategory###,12,###SITE:foobar###',
'expectedStartingPoints' => '42,4711,12,1',
'site' => new Site('some-site', 1, ['rootPageId' => 1, 'foobar' => 1, 'categories' => ['contentCategory' => 4711]]),
],
'one invalid settings' => [
'inputStartingPoints' => '42,12,###SITE:invalid###',
'expectedStartingPoints' => '42,12',
'site' => new Site('some-site', 1, ['rootPageId' => 1]),
],
'one valid and one invalid setting' => [
'inputStartingPoints' => '42,###SITE:invalid###,12,###SITE:categories.contentCategory###',
'expectedStartingPoints' => '42,12,4711,4712',
'site' => new Site('some-site', 1, ['rootPageId' => 1, 'categories' => ['contentCategory' => '4711,4712']]),
],
];
}

Expand Down

0 comments on commit f1b4f90

Please sign in to comment.