File Upload doesn't handle spaces in filename
| Project: | Webform |
| Version: | 5.x-1.10 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Upload a file with a space in the filename. When the e-mail notice is sent out or in the results table, the space (and any other special characters) are not being properly encoded. This fix is applied against 5.x-1.10 but should also be applied against 2.0 as well.
Here's the fix.
Index: file.inc
===================================================================
--- file.inc (revision 1171)
+++ file.inc (working copy)
@@ -303,7 +303,9 @@
*/
function theme_webform_mail_file($data, $component) {
$file = unserialize($data);
- $output = $component['name'] .": ". (!empty($file['filepath']) ? file_create_url($file['filepath']) : '') ."\n";
+ $cleanurl = cleanurl(file_create_url($filedata['filepath']));
+
+ $output = $component['name'] .": ". (!empty($file['filepath']) ? $cleanurl : '') ."\n";
return $output;
}
@@ -329,7 +331,9 @@
$form_item['#default_value'] = empty($filedata['filepath']) ? $filedata['error'] : $filedata['filepath'];
}
if ($filedata['filename']) {
- $form_item['#suffix'] = ' Download '. $filedata['filename'] .'' . $form_item['#suffix'];
+ $cleanurl = cleanurl(file_create_url($filedata['filepath']));
+
+ $form_item['#suffix'] = ' Download '. $filedata['filename'] .'' . $form_item['#suffix'];
if ($enabled) {
$form_item['#description'] = t('Uploading a new file will replace the current file.');
$form_item['#webform_current_file'] = $filedata;
@@ -446,3 +450,12 @@
return empty($filedata['filename']) ? '\,' : $filedata['filename'] .'\,'. (int)($filedata['filesize']/1024);
}
+function cleanurl($url) {
+ $cleanurl = urlencode($url);
+ $cleanurl = str_replace("+","%20",$cleanurl);
+ $cleanurl = str_replace("%3A",":",$cleanurl);
+ $cleanurl = str_replace("%2F","/",$cleanurl);
+
+ return $cleanurl;
+}
+

#1
this...
function theme_webform_mail_file($data, $component) {
$file = unserialize($data);
- $output = $component['name'] .": ". (!empty($file['filepath']) ? file_create_url($file['filepath']) : '') ."\n";
+ $cleanurl = cleanurl(file_create_url($filedata['filepath']));
+
+ $output = $component['name'] .": ". (!empty($file['filepath']) ? $cleanurl : '') ."\n";
return $output;
}
should actually be...
function theme_webform_mail_file($data, $component) {
$file = unserialize($data);
- $output = $component['name'] .": ". (!empty($file['filepath']) ? file_create_url($file['filepath']) : '') ."\n";
+ $cleanurl = cleanurl(file_create_url($file['filepath']));
+
+ $output = $component['name'] .": ". (!empty($file['filepath']) ? $cleanurl : '') ."\n";
return $output;
}
#2
Thanks, could you reroll and attach as file?
#3
This is the file.inc for 5.x-1.10 that urlencodes the URI, but preserves ://~
#4
This is the file.inc for 5.x-2.0 that urlencodes the URI, but preserves ://~
#5
Oh sorry I wasn't clear. Could you attach the patch as a file, not the entire file itself? Sorry for the trouble!
#6
Here's the 5.x-2.0 diff.
#7
Here's the 5.x-1.10 diff.
#8
I see the need for this, especially in the submitted e-mails. The implementation is a little wonky though, using urlencode then a strreplace on the encoding? Seems like we could just use rawurlencode and be done with it. How does this patch look as an alternative approach?
#9
Hm, I accidentally committed the 5.x version with another patch. I'll just leave it in there and commit to the 6.x version also. Please reopen if further correction is necessary. Thanks!
#10
Much cleaner than my fix. Thanks.
#11
Thanks for your patch also! I don't mean to be troublesome, but patches really help me review and commit changes. The first (inline) patch you posted was great except it was inline without the
<code>tags around it. The later patches should have been in the Unified format, but I worked with it alright. Thanks again!#12
Automatically closed -- issue fixed for two weeks with no activity.