Project

General

Profile

Actions

Bug #94852

closed

Importing YAML files with numeric keys yields unexpected results

Added by Johannes Nielsen over 3 years ago. Updated 5 months ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
-
Target version:
-
Start date:
2021-08-12
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
10
PHP Version:
7.3
Tags:
Complexity:
Is Regression:
Sprint Focus:

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'
Actions #1

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
Actions #2

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

Actions #3

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

Actions #4

Updated by Georg Ringer 5 months ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
Actions #5

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

Actions #6

Updated by Benni Mack 5 months ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF