Page MenuHomePhabricator

period ('.') is a valid character in a file name (foo.bar.jpg is not the same as foo.jpg)
Closed, ResolvedPublic

Description

Author: brianna.laugher

Description:
Hi,

A user at Commons reported getting an inappropriate warning:

When I do a trial upload of one image, I get an error "a file with a similar name already exists, choose another filename". Unfortunately the file that already exists is "drosera.jpg" (not my picture) and that blocks my "drosera.spatulata.flower.x16.jpg" and it will block all other Drosera images too.

I believe this is [[MediaWiki:fileexists-extension]] was introduced in r25481.

I believe it is caused because of this previous line in SpecialUpload.php:

list( $partname, $rawExtension ) = explode( '.', $file->getName(), 2 );

So in this case I think we have $partname = 'drosera', $rawExtension = 'spatulata'.

f ( $rawExtension != $file->getExtension() ) {
474 $nt_lc = Title::newFromText( $partname . '.' . strtolower( $ext ) ); We're not using the normalized form of the extension.
475
Normal form is lowercase, using most common of alternate
476 extensions (eg 'jpg' rather than 'JPEG').
477

478 // Check for another file using the normalized form...
479 $nt_lc = Title::newFromText( $partname . '.' . $file->getExtension() );

then since 'spatulata' != 'jpg', the new title ends up being 'drosera.jpg'. Hence the inappropriate error.

If '.' was not allowed in image titles that would work fine.

To fix it I suppose you could either do a regex string split thing, or else, do the explode and then join all but the last one back up again to form $partname.


Version: unspecified
Severity: minor

Details

Reference
bz13143

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 10:07 PM
bzimport set Reference to bz13143.
bzimport added a subscriber: Unknown Object (MLST).

Well the warning message sort of answers your question. It says "a file with a SIMILAR name already exists, choose another filename". If you press the ignore button, the file will be saves, with the exact name you provided, and it DOESN'T overwrite the other file (which is a "similar" but not identical) name.

Please let us know if you've got your answer here.

No, that's not the issue, Huji. The issue is that exploding based on the occurrence of '.' in the file name is the wrong way to find the extension. We should be going BACK from the end, rather than FORWARD from the beginning. I'm working on a patch for this now.

Oops! Sorry for my misunderstanding. Hopefully, the fix with be easy to achieve since PHP has lots of string functions which go backward in a string (although RegExp is an option too).