Repository navigation
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When an
imageorimagelistfield has noextensionsset, the defaults are built by intersecting['gif', 'jpg', 'jpeg', 'png', 'svg', 'avif', 'webp']withaccept_file_types.Collection::intersect()keeps the original keys, so disallowing a type in the middle of that list leaves a gap.For example, with
svgremoved fromaccept_file_types(a common hardening step) butavifandwebpstill 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:
The existing tests didn't catch this because the shipped
config.yamlallows neithersvg,avifnorwebp, so the intersection only trims the end of the list and the keys stay sequential.Fix
ContentTypesParser: reindexextensionswitharray_values()wherefile,filelist,imageandimagelistfields are already normalised to an array. This covers the defaults as well as anyextensionsset incontenttypes.yaml.file,filelistandimagelisttemplates: defaultextensionsto[]instead of'', likeimage.html.twigalready does, so an empty value is also passed as an array.Tests
Added
ContentTypesParserTest::testUploadFieldExtensionsAreListswith a fixture holding all four upload field types withoutextensions. It setsaccept_file_typeswithoutsvgand asserts that each field's extensions are a list that serialises as a JSON array. It fails without the fix (keys jump from3to5) and passes with it.