Opened 3 years ago
Last modified 3 years ago
#54078 new defect (bug)
Underscore appended to media file on upload
Reported by: | spielautomat4 | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 5.8 |
Component: | Upload | Keywords: | dev-feedback |
Focuses: | administration | Cc: |
Description
I noticed that a random underscore is appended to media files, when uploading them in an article. Im using the Classic Editor.
The original file name was:
AB-LET.2018.133.AXH1.jpg
Once uploaded, it became:
AB-LET.2018.133.AXH1_.jpg
There was no prior file uploaded with that name (at least the media gallery does not find any).
Change History (4)
#2
in reply to:
↑ 1
@
3 years ago
Replying to karpstrucking:
@spielautomat4 is this happening for all images or just this one in particular? if just this one, can you try renaming the file locally before uploading?
Other files upload properly, there no underscore will be appended.
I suppose, it's due to the periods and/or trailing number in the file name.
#3
in reply to:
↑ 1
@
3 years ago
I have done some more testing and can confirm, that it's due to the periods in the file name.
The trailing number is no problem. I have tried with another WordPress installation as well.
Test case 1:
AB-LET.2018.133.AXH1.jpg -> AB-LET.2018.133.AXH1_.jpg [FAULTY]
Test case 2:
AB-LET.2018.133.AXH.jpg -> AB-LET.2018.133.AXH_.jpg [FAULTY]
Test case 3:
AB-LET_2018_133_AXH1.jpg -> AB-LET_2018_133_AXH1.jpg [OK]
Test case 4:
AB-LET_2018_133_AXH.jpg -> AB-LET_2018_133_AXH.jpg [OK]
#4
@
3 years ago
- Keywords dev-feedback added; reporter-feedback removed
It looks like this is actually an intended function of sanitize_file_name()
(https://core.trac.wordpress.org/browser/tags/5.8/src/wp-includes/formatting.php#L2047)
/* * Loop over any intermediate extensions. Postfix them with a trailing underscore * if they are a 2 - 5 character long alpha string not in the allowed extension list. */ foreach ( (array) $parts as $part ) { $filename .= '.' . $part; if ( preg_match( '/^[a-zA-Z]{2,5}\d?$/', $part ) ) { $allowed = false; foreach ( $mimes as $ext_preg => $mime_match ) { $ext_preg = '!^(' . $ext_preg . ')$!i'; if ( preg_match( $ext_preg, $part ) ) { $allowed = true; break; } } if ( ! $allowed ) { $filename .= '_'; } } }
@spielautomat4 is this happening for all images or just this one in particular? if just this one, can you try renaming the file locally before uploading?