Page MenuHomePhabricator

Special:Upload should remove whitespace before file extension
Closed, ResolvedPublicFeature

Description

Whitespace in front of an image suffix, such as "Foobar .jpg" (notice the space character before ".jpg"), should be stripped away by Special:Upload. It too confusing to distinguish between:

File:Foobar.jpg
File:Foobar .jpg

etc.

after images are uploaded. The whitespace is usually a mistake anyway (in the original filename on the user's PC).

Right now, the whitespace is accepted as a valid


Version: 1.24rc
Severity: enhancement

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 22 2014, 3:08 AM
bzimport set Reference to bz65811.

Change 136307 had a related patch set uploaded by devunt:
Remove trailing spaces of filename on Special:Upload

https://gerrit.wikimedia.org/r/136307

Change 136307 abandoned by devunt:
Trim spaces and underscores from suggested filename on Special:Upload

Reason:
Move to new change

https://gerrit.wikimedia.org/r/136307

Change 192773 had a related patch set uploaded (by devunt):
Trim spaces and underscores from suggested filename on Special:Upload

https://gerrit.wikimedia.org/r/192773

Change 195001 had a related patch set uploaded (by Rillke):
Use mw.Title.newFromFileName for sanitization after source file selection

https://gerrit.wikimedia.org/r/195001

Change 429657 had a related patch set uploaded (by Gopavasanth; owner: Gopavasanth):
[mediawiki/core@master] Use mw.Title.newFromFileName for sanitization after source file selection

https://gerrit.wikimedia.org/r/429657

Change 429657 abandoned by Fomafix:
Use mw.Title.newFromFileName for sanitization after source file selection.

Reason:
This change contains some rebase mistakes. I rebased Ib9d2ae7584969284b047b4c681ffae25290d8c89 in https://gerrit.wikimedia.org/r/195001 PS7. Please continue there.

https://gerrit.wikimedia.org/r/429657

Change 192773 abandoned by Thiemo Kreuz (WMDE):
Trim spaces and underscores from suggested filename on Special:Upload

Reason:
No action in 4 years. The code this patch aims to change doesn't even exist any more.

https://gerrit.wikimedia.org/r/192773

Is this issue still open? May I work on this?

The bad behavior is still present. I can confirm that in MediaWiki 1.35.1, I can upload an image file and name it foo .jpg including a space character before the .jpg extension.

Aklapper added a subscriber: devunt.

@devunt: Hi, I'm resetting the task assignee due to inactivity. Please feel free to reclaim this task if you plan to work on this - it would be welcome! Also see https://www.mediawiki.org/wiki/Bug_management/Assignee_cleanup for more information - thanks!

Aklapper changed the subtype of this task from "Task" to "Feature Request".Feb 4 2022, 12:23 PM

Hi, any ideas on steps to reproduce this bug?

  1. On your hard drive, create an image file named Foobar .jpg with a space before the dot.
  2. Visit Special:Upload, browse to this filename, and select it.
  3. Notice that on Special:Upload, the Destination filename is Foobar_.jpg.

This ticket suggests that Special:Upload should strip away the space at this point, before uploading, so the Destination filename is Foobar.jpg without the space.

Diesel_kapasule changed the task status from Open to In Progress.Mar 9 2022, 1:20 PM
Diesel_kapasule claimed this task.

Hi! I have used str_replace in UploadFromFile.php to remove whitespace.
Tested the code locally, everything is working well. Please check.

Change 769429 had a related patch set uploaded (by Diesel kapasule; author: Diesel kapasule):

[mediawiki/core@master] Removing whitespace before file extension

https://gerrit.wikimedia.org/r/769429

If I understand your patch correctly, you're removing all whitespace from the name, instead of just trailing whitespace before the file extension. Is that what you meant to do?

$desiredDestName = str_replace( " ",
			"",
			$desiredDestName );

@maiden_taiwan , I had misunderstood the request. the whitespace removed is before the extension only . Thanks for asking further.Patch has been updated.

Thanks for the patch. I appreciate your work!

If I understand the patch correctly, it removes a single space character that occurs before any dot in the string. So it will miss this case:

My file                           .jpg

and it will remove a space incorrectly in this case, before ".bashrc".

Example of Linux .bashrc file.jpg

Here, ".bashrc" is a separate word that should have a space in front of it.

I think what you need here is code that identifies the file extension (i.e., the text after the final dot, not all dots) and removes all whitespace (not just one space character) before the dot. The whitespace could be any number of spaces, tabs, newlines, etc. That sounds to me like a regular expression replacement.

Also, I am not a MediaWiki developer, but does this change require any new unit tests to make sure it works on a variety of inputs?

Change 769429 abandoned by Diesel kapasule:

[mediawiki/core@master] Removing whitespace before file extension

Reason:

Merge Conflict failed to be resolved

https://gerrit.wikimedia.org/r/769429

Change 769429 restored by Diesel kapasule:

[mediawiki/core@master] Removing whitespace before file extension

https://gerrit.wikimedia.org/r/769429

Change 769429 abandoned by Diesel kapasule:

[mediawiki/core@master] Removing whitespace before file extension

Reason:

Merge Conflict failed to be resolved

https://gerrit.wikimedia.org/r/769429

Change 769429 restored by Diesel kapasule:

[mediawiki/core@master] Removing whitespace before file extension

https://gerrit.wikimedia.org/r/769429

Change 769429 abandoned by Diesel kapasule:

[mediawiki/core@master] Removing whitespace before file extension

Reason:

Merge Conflict failed to be resolved

https://gerrit.wikimedia.org/r/769429

Change 769429 restored by Diesel kapasule:

[mediawiki/core@master] Removing whitespace before file extension

https://gerrit.wikimedia.org/r/769429

Change 769429 abandoned by Diesel kapasule:

[mediawiki/core@master] Removing whitespace before file extension

Reason:

Ticket already solved

https://gerrit.wikimedia.org/r/769429

Ticket already resolved