Imagecache in particular fails when filenames include special chars like + or &.
#615418: image file with '+' sign or & in name not found by imagecache

I suggest the addition of a preg_replace to the file_create_filename function in that will replace these 'problem' characters with a dash or underscore.

Something like this:

$name = preg_replace('/[&\+\s]/i', '-', $name);

In this case any ampersand, plus sign, or whitespace char will be replaced with a dash. This is probably enough to prevent imagecache from breaking, and any other modules that may have issues. Though more special characters may need filtering out as well.

#3 drupal-791780b.patch576 byteswillvincent
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch drupal-791780b.patch. View
#1 drupal-791780.patch297 byteswillvincent
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch drupal-791780.patch. View
Members fund testing for the Drupal project. Drupal Association Learn more


willvincent’s picture

Status: Active » Needs review
297 bytes
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch drupal-791780.patch. View

This patch implements my proposed change outlined above

Status: Needs review » Needs work

The last submitted patch, drupal-791780.patch, failed testing.

willvincent’s picture

Status: Needs work » Needs review
576 bytes
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch drupal-791780b.patch. View

Rerolled patch from drupal base install dir.. simpletest *should* succeed this time. :)

Status: Needs review » Needs work

The last submitted patch, drupal-791780b.patch, failed testing.

YK85’s picture

geophysicist’s picture

function file_munge_filename($filename, $extensions, $alerts = TRUE) {
// drupal bug fix
+ $filename = str_replace('+', '-', $filename);
$original = $filename;

GuyPaddock’s picture

dedalu’s picture

Do not forget the '#'.

izmeez’s picture

Just stumbled on this issue and wondering if the transliteration module solves this. It seems to work quite well and I believe it is in D7.

dedalu’s picture

Thank you izmeez, transliteration module does the work!

klonos’s picture

Title: Special chars should be removed from filenames on upload » Special chars should be removed/replaced from filenames on upload.
Version: 6.16 » 6.x-dev
Category: bug » feature
Issue tags: +transliteration

Well, this issue's title makes it sound a lot like a feature request and AFAICT it affects all D6 and not just 6.16. Now, for D8 we got #567832: Transliteration in core in (yippy!!) which combined with #576180: Make the machine-name generation pluggeable could make real magic happen. What we have to do next is put it into good use for other places as well: #1842718: Use new Transliteration functionality in core for machine names

For D6/D7 we have the Transliteration module (and friends). So, what I'm trying to say is that perhaps we should close this almost-3-years-old issue now? After all D8 is scheduled/estimated for around September 2013, so I guess it doesn't make sense anyways. Perhaps if it's not breaking any APIs you can suggest for #567832: Transliteration in core to be backported to D7.

So, what say you? Should we close it and point people to Transliteration?

izmeez’s picture

1+ to close this.

willvincent’s picture

I agree it can be closed, but it would probably be a very good idea to point people to Transliteration in a rather prominent way. While those of us who have been around for a while know about and regularly use transliteration, for newcomers it's not obvious that it should be used, and with the huge number of contrib modules it's not unlikely that people will not find their way to the transliteration module.

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.