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;
+}
+
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | webform_file_url.patch | 1.75 KB | quicksketch |
| #7 | file.inc_.5.x-1.10.diff.txt | 986 bytes | dharmatech |
| #6 | file.inc_.5.x-2.0.diff.txt | 1.11 KB | dharmatech |
| #4 | file.inc_.5.x-2.0.txt | 18.54 KB | dharmatech |
| #3 | file.inc_.5.x-1.10.txt | 18.34 KB | dharmatech |
Comments
Comment #1
dharmatech commentedthis...
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;
}
Comment #2
quicksketchThanks, could you reroll and attach as file?
Comment #3
dharmatech commentedThis is the file.inc for 5.x-1.10 that urlencodes the URI, but preserves ://~
Comment #4
dharmatech commentedThis is the file.inc for 5.x-2.0 that urlencodes the URI, but preserves ://~
Comment #5
quicksketchOh sorry I wasn't clear. Could you attach the patch as a file, not the entire file itself? Sorry for the trouble!
Comment #6
dharmatech commentedHere's the 5.x-2.0 diff.
Comment #7
dharmatech commentedHere's the 5.x-1.10 diff.
Comment #8
quicksketchI 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?
Comment #9
quicksketchHm, 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!
Comment #10
dharmatech commentedMuch cleaner than my fix. Thanks.
Comment #11
quicksketchThanks 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!Comment #12
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #13
jadowd commentedThis 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?