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;
+}
+

Comments

dharmatech’s picture

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;
}

quicksketch’s picture

Thanks, could you reroll and attach as file?

dharmatech’s picture

StatusFileSize
new18.34 KB

This is the file.inc for 5.x-1.10 that urlencodes the URI, but preserves ://~

dharmatech’s picture

Version: 5.x-1.10 » 5.x-2.0
StatusFileSize
new18.54 KB

This is the file.inc for 5.x-2.0 that urlencodes the URI, but preserves ://~

quicksketch’s picture

Oh sorry I wasn't clear. Could you attach the patch as a file, not the entire file itself? Sorry for the trouble!

dharmatech’s picture

StatusFileSize
new1.11 KB

Here's the 5.x-2.0 diff.

dharmatech’s picture

Version: 5.x-2.0 » 5.x-1.10
StatusFileSize
new986 bytes

Here's the 5.x-1.10 diff.

quicksketch’s picture

StatusFileSize
new1.75 KB

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?

quicksketch’s picture

Status: Needs review » Fixed

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!

dharmatech’s picture

Much cleaner than my fix. Thanks.

quicksketch’s picture

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!

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

jadowd’s picture

This doesn't seem to be working at all for 6.2x. Was this not patched into the 6.2 branch?

What seems to be happening is that the file is saved into the named directory, however, it produces a link which is url encoded... The file is saved to disk with spaces in the file name, the link cannot return the file...

I am using nginex... not sure where the disconnect is being made.

thoughts?