backdrop / backdrop-issues

Issue tracker for Backdrop core.
144 stars 39 forks source link

User pictures: Uploading an unsupported image format throws irrelevant error (about non-image extensions) #6176

Open klonos opened 1 year ago

klonos commented 1 year ago

This is a follow-up to #4937 and #5917.

Steps To Reproduce

  1. Navigate to /admin/config/people/settings, and make sure that the "Enable user pictures" setting is enabled (enable it and save the settings if not).
  2. Edit a user account, and try to upload an .svg image in the "Personalization" vertical tab.

Actual behavior

A validation error is thrown 👍🏼 ...however only the first item in the error is relevant:

image

Here's the same error in textual format:

The specified file android.svg could not be uploaded.

  • Only images with the following extensions are allowed: png, gif, jpg, jpeg, webp.
  • Only files with the following extensions are allowed: png gif jpg jpeg webp txt doc xls pdf ppt pps odt ods odp docx docm pptx pptm xlsx xlsm.

Expected behavior

The second bullet point in the error should not be thrown, as the field only allows for images - not any type of supported document/file types.

klonos commented 1 year ago

PR up for review: https://github.com/backdrop/backdrop/pull/4479

In user_validate_picture() we were specifying multiple validators, one of which is 'file_validate_is_image'. file_validate_is_image(), which is what this validator calls, is throwing the "Only images with the following extensions are allowed" error. In file_save_upload() though, we are adding a 'file_validate_extensions' validator when one has not been explicitly added (which is true for user_validate_picture()), and that is what eventually throws the second "Only files with the following extensions are allowed" error. So the PR is checking if 'file_validate_is_image' exists in the list of validators, and if that is the case, it skips adding a 'file_validate_extensions' validator on top of that.

avpaderno commented 1 year ago

Yes, those errors are quite confusing, especially because they seem to suggest that a .doc file is acceptable as image. (I know that Unix-like systems do not use the extension to recognize the file type, but saying file with .doc extension is understood as Word file by most people.)

avpaderno commented 1 year ago

(As side note, if I were to upload an image to use for my user account, I would immediately select the .face file on my computer, which is a PNG image, and its purpose is exactly to "represent" me on my computer. The second validator would tell me that a file with .doc extension is acceptable, but a file with .face extension is not. 😅)