Bug #94852
closedImporting YAML files with numeric keys yields unexpected results
100%
Description
When using imports in YAML files (e.g. in forms framework), numeric keys are not respected because the YamlFileLoader calls ArrayUtility::replaceAndAppendScalarValuesRecursive
which in turn calls array_merge
, which does not respect numeric keys.
As an example, say one has three YAML files:
#imports.yaml:
imports:
- { resource: './file1.yaml' }
- { resource: './file2.yaml' }
#file1.yaml:
TYPO3:
CMS:
Form:
prototypes:
standard:
formElementsDefinition:
Form:
formEditor:
editors:
900:
selectOptions:
35:
value: 'FirstValue'
label: 'First option'
#file2.yaml:
TYPO3:
CMS:
Form:
prototypes:
standard:
formElementsDefinition:
Form:
formEditor:
editors:
900:
selectOptions:
45:
value: 'SecondValue'
label: 'Second option'
The expected result would be:
TYPO3:
CMS:
Form:
prototypes:
standard:
formElementsDefinition:
Form:
formEditor:
editors:
900: # 900 is respected as key
selectOptions:
35:
value: 'FirstValue'
label: 'First option'
45:
value: 'FirstValue'
label: 'First option'
However, the actual result is
TYPO3:
CMS:
Form:
prototypes:
standard:
formElementsDefinition:
Form:
formEditor:
editors:
# array_merge is called on the editors array, so that numeric keys get lost
0:
selectOptions:
35:
value: 'FirstValue'
label: 'First option'
1:
selectOptions:
45:
value: 'FirstValue'
label: 'First option'
As a workaround, one can add an empty non-numeric key to the second import - given that the order is known, which could be reversed if the corresponding feature-flag is set, so it would be better to add this to all imports:
#file2.yaml:
TYPO3:
CMS:
Form:
prototypes:
standard:
formElementsDefinition:
Form:
formEditor:
editors:
_: # This makes this an associative array and yields the desired result plus this empty property
900:
selectOptions:
45:
value: 'SecondValue'
label: 'Second option'
Updated by Johannes Nielsen over 3 years ago
- Subject changed from Importing YAML files with numberic keys yields unexpected results to Importing YAML files with numeric keys yields unexpected results
Updated by Gerrit Code Review 5 months ago
- Status changed from New to Under Review
Patch set 1 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/84980
Updated by Gerrit Code Review 5 months ago
Patch set 1 for branch 12.4 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/84957
Updated by Georg Ringer 5 months ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset 911b01d0644026723366d8e0249dc9e492577706.
Updated by Georg Ringer 5 months ago
Hi Johannes,
the issue has been fixed in at least 12. I just added a test to avoid potential regressions