craftcms / cms

Build bespoke content experiences with Craft.
https://craftcms.com
Other
3.22k stars 624 forks source link

[4.x]: Asset filenames not saved with spaces #11475

Open andyra opened 2 years ago

andyra commented 2 years ago

What happened?

Description

When uploading a file with space characters in the filename, it gets saved on the volume with dashes instead of spaces. This is a problem because the filename in the database URL encodes the spaces as %20, but the file on the volume uses dashes, so the assets always return a 404.

I'm using DigitalOcean Spaces as my volume.

Steps to reproduce

  1. Upload a file with spaces in the name (ex: This is an image.jpg)
  2. Output the URL of the asset in a view (ex: {{ url }})
  3. The rendered URL (This%20is%20an%20image.jpg) doesn't match the actual file that was uploaded to the volume (This-is-an-image.jpg)

Expected behavior

Files uploaded to the volume should retain spaces (This is an image.jpg)

Actual behavior

Files uploaded to the volume replace spaces with dashes (This-is-an-image.jpg)

Craft CMS version

4.0.5

PHP version

8.1.4

Operating system and version

Darwin 21.5.0

Database type and version

MySQL 8.0.28

Image driver and version

GD 8.1.4

Installed plugins and versions

brandonkelly commented 2 years ago

I’m not able to reproduce this. How are you uploading the files, exactly?

Also, are you overriding the convertFilenamesToAscii or filenameWordSeparator config settings?

andyra commented 2 years ago

Oh wow, I didn't see that there was a preference for this! Changing filenameWordSeparator to false fixed the issue. It might make sense to either have this be true by default, or at least have the URL returned by the asset match the uploaded file. Thanks for the quick response!

brandonkelly commented 2 years ago

@andyra I’d still like to get to the bottom of why the URLs are incorrect, though. When I leave the setting to its default value ('-'), uploaded asset URLs reflect their filenames, with dashes.

So can you tell me how you are uploading the assets? And for assets where this issue occurred, do their filenames in the control panel show dashes or spaces?

andyra commented 2 years ago

I tried creating assets from the Assets page in the CP, via an Asset field (within a Matrix block), and via a FeedMe import, and they all had the same issue.

The filenames in the CP all had spaces. The only reason I knew they were saved with dashes was by looking on the Spaces volume on my Digital Ocean account.

brandonkelly commented 2 years ago

We’re still unable to reproduce, either with a Local filesystem or with DO Spaces. Going to leave the issue open in case anyone else runs into it. Maybe another clue will come up.