Problem/Motivation
The module unconditionally appends FileIsSvgImage to #upload_validators so when you upload a JPEG or PNG via the Media Library widget, Drupal runs FileIsSvgImageConstraintValidator and the uploaded file is rejected because it isn't an SVG.
Steps to reproduce
Enable SVG Image Field, the SVG Image Field Media Bundle submodule, and core Media Library module.
Configure the Article content type to contain a Media field with Image and Vector Image types available.
Go to /node/add/article, click Add Media and upload a JPEG to the Media Image field where the extensions jpg, jpeg are allowed using the Media Library widget.
Expected result
User is able to upload JPEG image to the Image media bundle via the Media Library popup widget.
Actual result
User is prevented from uploading JPEG image to the Image media bundle with error message:
The specified file [filename].jpeg could not be uploaded.
Only files with mime type image/svg+xml,image/svg are allowed. Mime type detected image/jpeg

Proposed resolution
Only apply SVG validation when the media type is svg/Vector Image.
Remaining tasks
Merge request to come.
User interface changes
None
API changes
None
Data model changes
None
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | 3590084-after.png | 183.64 KB | jwilson3 |
| #4 | 3590084-before.png | 249.08 KB | jwilson3 |
Issue fork svg_image_field-3590084
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
jwilson3Comment #4
jwilson3Comment #6
jwilson3I encountered
FileIsSvgImageConstraintValidatorand prepared an MR-first fix for review.What this change does:
FileIsSvgImageis only added when the selected media type uses thesvgmedia source.imageandvector_imageand verifies the SVG validator is only present on the SVG-backed form.Scope of changes:
svg_image_field.moduletests/src/Kernel/MediaLibraryUploadValidationTest.phpSteps to test:
FileIsSvgImageConstraintValidator; after the fix it is accepted.Comment #7
jwilson3The normal CI pipeline passed all tests. I then ran the
tests-onlyCI Job, which revertedsvg_image_field.module, so it ran the new regression test against the pre-fix behavior. In that state, the failure is expected:testSvgUploadValidatorsAreScopedToSvgMediaTypefails because the non-SVG Media Library upload form still hasFileIsSvgImageattached.This result proves the test catches the bug when the fix is absent.
I also tested locally with and without the fix applied.
Without the fix: I see the same error message as OP (see screenshot in IS).
With the fix: I am able to successfully upload a JPEG image via Media Library widget popup.
Comment #9
jwilson3