The regular expression used to find the new name for the uploaded file is possibly incorrect in that if there is an occurrence of a filename like this:

abcdefg_1.live_1.jpg

It will get turned into this:

abcdefg.live_1.jpg

It's not likely to happen very often, but I think that the line may need to change to:

$desired_destination = preg_replace('/_[0-9]+\.([^\.]*)$/', '.$1', $uri);

Which then gives:

abcdefg_1.live.jpg

CommentFileSizeAuthor
#2 upload_replace_fix_regex.patch394 bytesalexh

Comments

elijah lynn’s picture

alexh’s picture

StatusFileSize
new394 bytes

Hi,
this issue was quite serious in our case when we had filenames of this pattern:
item_1.1.pdf
item_2.1.pdf

After updating these files, the resulting filenames of the current revision were the following:
item_2.1_0.pdf (for the previously named item_1.1.pdf !!)
item.1_0.pdf (for the previously named item_2.1.pdf)
The filenames of the original revision were unchanged.

This messed up a lot of files until I realised it and took me some time to correct all filenames.

The suggestion from tobyontour to update the regular expression is good. It fixed the issue for me. Only the second parameter should be $new_file->uri.

I created a patch for it. Looking forward that it gets applied.