When using a token for the filename that includes space characters, the subsequent transliteration doesn't replace the space. It does replace non-ascii characters however. I've tested this using Image Field, and in the thumbnail preview of the image it's apparent that Transliteration properly replaces whitespace characters before FileField Paths goes ahead and makes its token replacements. The token then get passed through Transliteration again, but doesn't handle the whitespace.
I've looked at the code for both modules, and what's happening is that Transliteration does its non-ascii character transliteration in a separate function from the filename sanitizing (which includes replacing spaces). The former is handled in the transliteration_get(), which FF Paths calls, and the latter in transliteration_clean_filename(), which Transliteration only calls from the hook_init() if it finds anything in $_FILES, so this whole step is bypassed.
I've included a fix for filefield_paths.module (line 307).
Old code:
// Transliterate string
if (module_exists('transliteration') && variable_get($settings .'_transliterate', 0)) {
$value = transliteration_get($value);
}
Fix:
// Transliterate string
if (module_exists('transliteration') && variable_get($settings .'_transliterate', 0)) {
$value = transliteration_get($value);
$value = transliteration_clean_filename($value);
}
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | filefield_paths.patch | 489 bytes | illuminaut |
Comments
Comment #1
illuminaut commentedSorry, a bit trigger-happy. Just realized that transliteration_clean_filename() already has a function call to transliteration_process(), which would now get called twice. So the transliteration_get($value) call is unnecessary. Just replace it with transliteration_clean_filename($value). Tested this with a number of variations and so far so good.
Comment #2
illuminaut commentedTested it some more and unfortunately this has some nasty side-effects. There is something really funky going on when the preg_replace of the cleanup function gets called. The file gets renamed quite strangely and is put in the wrong directory. Needs some more investigation.
Comment #3
illuminaut commentedHere's a new shot at it.
Comment #4
decipheredHi illuminaut,
Thanks for the good work on the patch.
I've tested it and it looks good.
Will be committed very soon.
Comment #5
decipheredCommitted to head