Problem/Motivation
In #2911319: Provide a single command to install & run Drupal, Drupal got the ability to be installed and served using the quick start command. If you upload files whose name contains special characters - like é, ñ, and ç - it is not possible to access the them from the browser. A similar situation happens with image fields, but here the error is more subtle to notice. If the image file name contains a special character, image styles will be served properly, but the original image will not. The path to the image style is different, but it does not affect this issue. What makes a difference is that by default, image style URLs include a derivative token itok query string parameter. If present, the image will be load properly.
While debugging the problem, I thought it might be an issue caused by using the PHP built-in server. But after stopping Drupal's quick-star/server commands and executing php -S 127.0.0.1:8888
, the files were served properly.
I think this is something that might occur during contribution days.
Steps to reproduce
* Install and serve Drupal using the quick-start / server commands:
php core/scripts/drupal quick-start
php core/scripts/drupal serve
* Attach a file or image field to a content type. The image field in the article content type can be used for testing.
* Upload a file with a special character in its name. For example: español.jpg
, français.png
, or página.txt
.
* Try to access/download the file. If it is an image, make sure to try to access the original file does not contain a derivatite token itok query string parameter for the error to surface. In the URLs below, the special characters are encoded.
http://127.0.0.1:8888/sites/default/files/p%C3%A1gina.txt // this fails
http://127.0.0.1:8888/sites/default/files/2020-03/espan%CC%83ol.jpg // this fails
http://127.0.0.1:8888/sites/default/files/styles/large/public/2020-03/espan%CC%83ol.jpg // this fails
http://127.0.0.1:8888/sites/default/files/styles/large/public/2020-03/espan%CC%83ol.jpg?itok=AcY_Z8bl // this works
Note, the files are uploaded with the proper name and can be access from the file system. The problem in when they are served by Drupal.
Proposed resolution
Document the issue until a solution is found. Possible places to do it:
* QUICKSTART section in drupal/web/core/INSTALL.txt
* https://www.drupal.org/node/2969396
* https://www.drupal.org/docs/installing-drupal/drupal-8-quick-start-command
This might not be related, but tranliterating files uploads might help with this as well. See #3032390: Add an event to sanitize filenames during upload.