Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
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 file.inc 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.
Comment | File | Size | Author |
---|---|---|---|
#3 | drupal-791780b.patch | 576 bytes | willvincent |
#1 | drupal-791780.patch | 297 bytes | willvincent |
Comments
Comment #1
willvincent CreditAttribution: willvincent commentedThis patch implements my proposed change outlined above
Comment #3
willvincent CreditAttribution: willvincent commentedRerolled patch from drupal base install dir.. simpletest *should* succeed this time. :)
Comment #5
YK85 CreditAttribution: YK85 commentedsubscribing, coming from #615418: image file with '+' sign or & in name not found by imagecache
Comment #6
geophysicist CreditAttribution: geophysicist commentedin file.inc
function file_munge_filename($filename, $extensions, $alerts = TRUE) {
// drupal bug fix
+ $filename = str_replace('+', '-', $filename);
$original = $filename;
Comment #7
GuyPaddock CreditAttribution: GuyPaddock commentedThere's a patch with a different approach in #880098: Escape characters in filenames are escaped and mis-interpreted by ImageCache.
Comment #8
dedalu CreditAttribution: dedalu commentedDo not forget the '#'.
Comment #9
izmeez CreditAttribution: izmeez commentedJust stumbled on this issue and wondering if the transliteration module http://drupal.org/project/transliteration solves this. It seems to work quite well and I believe it is in D7.
Comment #10
dedalu CreditAttribution: dedalu commentedThank you izmeez, transliteration module does the work!
Comment #11
klonosWell, 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?
Comment #12
izmeez CreditAttribution: izmeez commented1+ to close this.
Comment #13
willvincent CreditAttribution: willvincent commentedI 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.