WordPress.org

Make WordPress Core

Opened 8 weeks ago

Closed 8 weeks ago

Last modified 4 weeks ago

#54067 closed enhancement (invalid)

Filenames shouldn't hold dots

Reported by: bedas Owned by:
Milestone: Priority: normal
Severity: minor Version:
Component: Media Keywords:
Focuses: Cc:

Description

When uploading a file (attachment) to WP (posts or else) and said file has dots in its name (like it is the case for Screenshots) then the File URL becomes something like
https://site.tld/wp-content/uploads/Screenshot-2021-09-03-at-13.10.46.png

While that is expected perhaps WP Could check if there are dots in the filename and either replace them by a dash or fully reject the upload.

Dots in the filename create issues when creating download links, for example, where then the downloaded attachment ends up being a format of "46", instead of "png", taken in above example.

It should be great if this can be avoided, as dots in filenames are likely not a good idea to have anyway, but telling that the consumers is rather a exorbitant and almost impossible task.

Of course we could validate uploads on our own, however I think it would be a good thing to have directly in the media uploader.

Happy to stand corrected :)

Change History (4)

#1 @joyously
8 weeks ago

It sounds like the problem is in the use of the name, not the upload. A dot is a valid character and limiting their usage now would not solve anything for existing files with dots.
Is your example of a download getting the wrong extension from core or a plugin?

#2 @bedas
8 weeks ago

  • Keywords 2nd-opinion removed
  • Resolution set to invalid
  • Status changed from new to closed

I am not relying on plugins, however, you are right that there was an error in my approach.

I used <a download="'.$filename.'" href="'.$fileurl.'">handle</a> (where of course the $vars are previously dynamically populated).
That generates a link where the download attribute has a couple dots too many in it, and thus creating a downloaded filename of file.name.more.dots

By changing that to use another, non dotted filename (stripping them prior to usage) resolves the issue.

Sorry the unnecessary trac ticket.

Closed as non-issue.

#3 @desrosj
4 weeks ago

  • Milestone Awaiting Review deleted

Changing the resolution to invalid as that's the default catch all resolution. fixed is reserved for closed tickets where a change was made to fix the problem.

#4 @desrosj
4 weeks ago

Oops, apologies! invalid already was the resolution. I had misread the ticket.

Note: See TracTickets for help on using tickets.