Skip to content

fix(config): reindex upload field extensions so they serialise as a JSON array - #3831

Open
Vondry wants to merge 1 commit into
bolt:6.1from
Vondry:fix/upload-field-extensions-list
Open

Vondry wants to merge 1 commit into
bolt:6.1from
Vondry:fix/upload-field-extensions-list

Conversation

@Vondry

@Vondry Vondry commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Problem

When an image or imagelist field has no extensions set, the defaults are built by intersecting ['gif', 'jpg', 'jpeg', 'png', 'svg', 'avif', 'webp'] with accept_file_types. Collection::intersect() keeps the original keys, so disallowing a type in the middle of that list leaves a gap.

For example, with svg removed from accept_file_types (a common hardening step) but avif and webp still allowed, the field definition ends up with:

{"0":"gif","1":"jpg","2":"jpeg","3":"png","5":"avif","6":"webp"}

That's passed to the editor as a JSON object instead of an array, so clicking "Add new image" fails with:

TypeError: this.extensions.map is not a function
    at a.acceptedExtensions (bolt.js)

The existing tests didn't catch this because the shipped config.yaml allows neither svg, avif nor webp, so the intersection only trims the end of the list and the keys stay sequential.

Fix

  • ContentTypesParser: reindex extensions with array_values() where file, filelist, image and imagelist fields are already normalised to an array. This covers the defaults as well as any extensions set in contenttypes.yaml.
  • file, filelist and imagelist templates: default extensions to [] instead of '', like image.html.twig already does, so an empty value is also passed as an array.

Tests

Added ContentTypesParserTest::testUploadFieldExtensionsAreLists with a fixture holding all four upload field types without extensions. It sets accept_file_types without svg and asserts that each field's extensions are a list that serialises as a JSON array. It fails without the fix (keys jump from 3 to 5) and passes with it.

…SON array

The default image extensions are intersected with accept_file_types, which
keeps the original keys. Disallowing a type in the middle of the list (e.g.
removing svg while keeping avif and webp) leaves a gap, so the extensions are
JSON-encoded as an object and the editor fails with
"this.extensions.map is not a function" when adding an image.

Reindex the extensions of file, filelist, image and imagelist fields with
array_values(), and default the file, filelist and imagelist templates to an
empty array like the image template already does.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant