Problem/Motivation
I am not sure this is a bug in this module, or a bug in core, but when a file contains a character such as %
the link to the file returns the an unecoded url which results in a 400 error from S3 when linking to it.
When using Drupal's standard public or private streams the urls are encoded correctly.
Steps to reproduce
I have only tested using:
- Drupal core 10.2.6
- S3FS 8.x-3.4
- S3 bucket
Use a file with a % in the filename - e.g this is 100% not working.pdf
Evaluating this code - (taken from what is happening in template_preprocess_file_link
)
$file_url_generator = \Drupal::service('file_url_generator');
$url = $file_url_generator->generate($file->getFileUri());
$url->toString();
When using Drupal's public file system the URL is returned as: /sites/default/files/this%20is%20100%25%20not%20working.pdf
When using the S3 public system take over the following URL is returned: https://buckerurlexample/public/this is 100% not working.pdf?VersionId=....
With the lack of encoding in the link - I get a 400 response from S3 - visiting https://buckerurlexample/public/this%20is%20100%25%20not%20working.pdf?VersionId=....
returns the file as expected.
Debugging it looks like the URI gets encoded in the UnroutedUrlAssembler::buildLocalUrl
method for the standard public / private files - https://git.drupalcode.org/project/drupal/-/blob/10.2.6/core/lib/Drupal/...
However when it is an external URL is no encoding on the URI passed in buildExternalUrl
Proposed resolution
TBC
Remaining tasks
TBC
User interface changes
n/a
API changes
TBC
Data model changes
n/a