I have a client for which I use webform to allow people to apply for employment positions. when I allow users to attach their resume's to the form submission, everything works fine, until HR tries to access the resume file attachment via the emailed link or the link in the submission results for the form.

What is happening is that drupal is swapping spaces in the url for the encoded value of %20, but the line 586 of components/file.inc is setting the url value differently...

$file_url = file_create_url($info['dirname'] .'/'. rawurlencode($info['basename']))

Sets the value of a space in the url as %2520

When I remove the function call to rawurlencode I see that the code works much better.

can I submit a patch for this and get you guys to make the change into the code base?

Thanks,

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jadowd’s picture

FileSize
543 bytes

Here is the patch!

quicksketch’s picture

Title: url generation for file component is broken » File component double-encodes URLs in e-mails

Something tells me this is going to fix it in one place but break it in another. I bet this will make links in e-mails work (since they're plain text) but break it when the submission is viewed in a web browser.

jadowd’s picture

I have tested in both places... it was broken in both places. It seemed to me that the URL was being parsed twice or something.

If you have a better solution, I am totally amicable.

quicksketch’s picture

Hm strange, I'm sure that urlencode() was put there for a reason. Perhaps a change in Drupal core has made it unnecessary.

jadowd’s picture

it was rawurlencode... and, I think that you may be right. My guess is that the function call "file_create_url" may have something to do with it...

quicksketch’s picture

Version: 6.x-2.9 » 6.x-3.6

This call to rawurlencode() still exists in the 3.x version, though I'm still uncertain about this change. This won't be fixed in the 2.x version so I'm moving to the latest version.

quicksketch’s picture

Title: File component double-encodes URLs in e-mails » File component double-encodes private file URLs in e-mails
Status: Active » Postponed

So it looks to me like we're doing the right thing if the file is a public file, but the double-encoding would only happen if you have the private file system enabled (admin/settings/file-system). Public files are not escaped but private files are run through url(), which ultimately calls drupal_encodeurl().

Considering many more users use public files than private files (and with good reason, private files are really, really slow), I think it's a good idea to hold-off on this change. If we can come up with a universal solution I'd be happy to hear it, but for now I think I'd recommend any of the following:

- Install the transliteration.module, which will make safe-names for your uploaded files and prevent this situation.
- Use public files instead of private files.

kim.pepper’s picture

I get this issue in emails (both plain and html) when using public files. Links to files are double-encoding spaces.

K

Dave Reid’s picture

Version: 6.x-3.6 » 6.x-3.x-dev
Status: Postponed » Needs review
FileSize
925 bytes

Patch attached to fix this issue for users of private files only. Does not apply to 7.x-3.x.

Dave Reid’s picture

quicksketch’s picture

Status: Needs review » Fixed

Thanks Dave, committed finally.

Status: Fixed » Closed (fixed)

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

rterrero’s picture

#9 was perfect for me.
Thanks!