Problem
Ran into an issue I have a view that is displaying content, that content has a file field, Image title etc. I am displaying image and title, and have it so when I click the image, the file downloads this works every time except if the file has a space in it, I believe it is trying to encode the token a second time. Tested this with a fresh install of D8.
For example
Upload file name: "test file.txt"
Upload field Views "test%20file.txt"
Rewrite url field views "test%2520file.txt"
Steps to reproduce
- Install latest version of Drupal
- On the Basic Page content type, add a file field
- Create a text file with a space in the filename, i.e. 'test file.txt'
- Create a new basic page and upload 'test file.txt' in the file field you just added
- Create a view that displays fields of content type 'Basic page'
- In the view, add the file field. Choose formatter: url to file.
- In the view, edit the file field. Click 'Rewrite results' and check 'Output this field as a custom link' with Link path: {{ field_file }} (or whatever token is in your case - see replacement patterns)
- Apply and save the view
- The view will display /sites/default/files/2022-05/test%20file.txt
but clicking it will result in a 404 as it leads to /sites/default/files/2022-05/test%2520file.txt
(notice the double encoding in the filename).
Comments
Comment #13
tintoTested this on a local install of Drupal 9.4.x and this issue still persists. Updating the issue summary with some clear steps to reproduce.
This double encoding problem has spawned a number of similar/related issues in other modules' issue queues, i.e.:
#3194561: Already encoded URLs are double-encoded, creating broken redirects
#1451868: Add Redirect form breaks URLs containing spaces or %20
#3034581: Videos with spaces in file name double encoded.
#2058459: Filename with spaces
There is also feature request discussed here, that could serve as a good workaround once implemented: #2492171: Provide options to sanitize filenames (transliterate, lowercase, replace whitespace, etc)