Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

%20 injected in to key id for virtual downloadable simple product #3012

Closed
luzpaz opened this Issue · 21 comments

6 participants

@luzpaz

As per: http://wordpress.org/support/topic/invalid-virtual-download-key-id-bug

Running WC 2.0.8
Have 1 simple product w/ 3 virtual downloadable PDFs bundled
When order is complete the customer receives invoice with the following three download URLs:

http://blah.com/?download_file=3284&order=order_51758569a9f61&email=blah.blah@gmail.com&key=6ac68fb90702a72a7ef9c508025583a4

http://blah.com/?download_file=3284&order=order_51758569a9f61&email=blah.blah@gmail.com&key=bad6a275f58467d31629a642f876b063

http://blah.com/?download_file=3284&order=order_51758569a9f61&email=blah.blah@gmail.com&key=43525530dc7761b931d92ff%203c0c1b748

The key ids:

  1. 6ac68fb90702a72a7ef9c508025583a4
  2. bad6a275f58467d31629a642f876b063
  3. 43525530dc7761b931d92ff%203c0c1b748

Notice the third one has more chars than the previous 2, and is coincedentally returning an Invalid download page. It's showing a 500 in the apache access.log file when I try to download the 3rd file.

Turns out the %20 = white space and when removed from the URL allows the file to be downloaded.
How can this be avoided?

EDIT: spelling, title, clarifications

@mikejolley
Owner

@luzpaz can you look in your download permissions table for that order ID and tell me if the white space is there, or if its coming from somewhere else.

@luzpaz

@mikejolley I checked the download permissions table on the product page. Using the 'Inspect Element' browser function I looked at the 'Revoke Access' button for that file

type="button" rel="3284,43525530dc7761b931d92ff3c0c1b748" class="revoke_access button"

as well as the Downloads Remaining input:

input type="hidden" name="download_id[2]" value="43525530dc7761b931d92ff3c0c1b748"

As you can see there is no %20 to be found.

@mikejolley
Owner

I cannot find out where it would be inserted. Please check the DATABASE as I said in case its there, but being filtered out in admin.

And try sending an invoice using the plain text email (See WC > Settings > Emails) in case the email client is inserting it.

@luzpaz

@mikejolley Oh, I get you now, you meant the database directly. Sorry
So, the wp_woocommerce_downloadable_product_permissions doesn't show any whitespaces in the ID

I looked for the option of sending plain text emails (in WC > Settings > Emails) and could not find that option. Where is it?

@luzpaz

@mikejolley sending plain text emails, how? Not locating that in the WC > Settings > Emails GUI. Do you mean that I make a simple text template for it ?

@mikejolley
Owner

@luzpaz WC > Settings > Emails, 'Customer Invoice', then there is a dropdown to select multipart, html or plain text.

@luzpaz

@mikejolley Thank you for the clarification.
Good news: The id has no whitespace when the plain text template is used! I was able to download the file no problem via the plain text invoice. Hope this helps.

@mikejolley
Owner

Kinda helps. I think it may be wordwrap http://php.net/manual/en/function.wordwrap.php

@mikejolley
Owner

Can't find a wordwrap doing it. Can you try another mail client?

I'm either going to need to clean up the space if present, or find out whatever is adding it.

@luzpaz

@mikejolley when you say 'try another mail client' are you asking for me to send the emails to an email provider other than google?

@mikejolley
Owner

Client. Outlook, mail.app.. Or a different email provider. Google do some funky search/replace in emails so I'm wondering if that could be affecting the strings. In which case, a cleanup function would be the only option.

@luzpaz

@mikejolley Oh wow, you're right, it may be a funky gmail thing. I was able to download the file no problem using a Yahoo web account. There was no whitespace in the ID name

@mikejolley mikejolley reopened this
@mikejolley
Owner

Can you confirm that works?

@luzpaz

Confirmed! Thanks Mike!

@luzpaz luzpaz closed this
@elflo

Hi!

I'm encountering the same issue of space characters embedded into certain download links. I've checked into the woocommerce_downloadable_product_permissions table, and the download_id stored there seems to be fine (no whitespace, no %20 characters). However, the faulty links have been observed using various email services (Yahoo, Live, etc). I am using the Woocommerce Amazon S3 extension as well, if that helps pinpoint the issue.

Any ideas?

@designloud

Hey @mikejolley , hope you have been doing well, I had a client email today with the same problem (using latest version of Woocommerce and also using Amazon S3 extension) I am not sure plain text will be an option for them but is this something that can be fixed by adding "/n" in the content of the emails or doing anything in the class-wc-order.php file here:
$file_urls[ $_product->get_file_download_path( $result->download_id ) ] = add_query_arg( array( 'download_file' => $download_file, 'order' => $this->order_key, 'email' => $user_email, 'key' => $result->download_id ), trailingslashit( home_url() ) );

Im not sure why but the %20 is being added randomly to some download links in client emails, and I would like to see if I can tell them anything else besides have their customers check from a different mail client or use a text based email?

I am happy to help if you can suggest a fix or point me to the right place. Thanks for your time, I know you are busy

@scottbasgaard

Have seen this issue pop up today in a ticket as well.

Looks like some services like Outlook has issues handling this and breaks the link. Gmail, etc. are okay.

@MauriceW2

Using the Woocommerce v2.0.19, NO Amazon S3. The downloadfiles are just stored on a folder outside the web root. About 50% of the emails with download links contains the %20 character.

I saw that white space fix #3012 is already implemented in v2.0.19, but it does not work here. I do know that this is absolutely unworkable.

@designloud

@MauriceW2 I was able to fix it on my end by copying the Woocommerce > templates > emails folder over to my theme folder and then open email-order-items.php. In there look for this section:

// File URLs
            if ( $show_download_links && $_product->exists() && $_product->is_downloadable() ) {

                $download_file_urls = $order->get_downloadable_file_urls( $item['product_id'], $item['variation_id'], $item );

                $i = 0;

                foreach ( $download_file_urls as $file_url => $download_file_url ) {
                    echo '
'; $filename = woocommerce_get_filename_from_url( $file_url ); if ( count( $download_file_urls ) > 1 ) { echo sprintf( __('Download %d:', 'woocommerce' ), $i + 1 ); } elseif ( $i == 0 ) echo __( 'Download:', 'woocommerce' ); echo ' ' . $filename . ''; $i++; } }

and replace this line:

echo ' '  . $filename . '';

with this:

echo ' ' . "\n" . $filename . '';

UPDATE: GitHub was stripping out some of the code so I also made a paste of it so you could see what I mean here: http://pastebin.com/ua037bXP

Cheers

@MauriceW2

Hi designloud, Thanks for pointing that out. I did what you suggested and it looks like its working! Fantastic. Thank you!

After this change, I did discover something weird, which is that the order of download files is completely messed up now.

It was organized like this:

Download 1: www.mysite.nl-instructions.zip
Download 2: www.mysite.nl-part1.zip
Download 3: www.mysite.nl-part2.zip
Download 4: www.mysite.nl-part3.zip
Download 5: www.mysite.nl-part4.zip
Download 6: www.mysite.nl-part5.zip
Download 7: www.mysite.nl-part6.zip
Download 8: www.mysite.nl-bonus1.zip
Download 9: www.mysite.nl-bonus2.zip
Download 10: www.mysite.nl-bonus3.zip
Download 11: www.mysite.nl-bonus4.zip

Now it's a mess:

Download 1: www.mysite.nl-part2.zip
Download 2: www.mysite.nl-bonus3.zip
Download 3: www.mysite.nl-bonus1.zip
Download 4: www.mysite.nl-instructions.zip
Download 5: www.mysite.nl-bonus2.zip
Download 6: www.mysite.nl-bonus4.zip
Download 7: www.mysite.nl-part1.zip
Download 8: www.mysite.nl-part3.zip
Download 9: www.mysite.nl-part6.zip
Download 10: www.mysite.nl-part5.zip
Download 11: www.mysite.nl-part4.zip

So I'm very happy that at least the links seem to work :-). Any ideas how to get the file order right again?

@designloud

@MauriceW2 Hmm, weird.. All that should have been added or changed in that file should have been just adding the . "\n" before the . $filename

All this does is add a new line (line break) to the link so it should have nothing to do with the order which makes me believe that some sort of error was made somewhere along the lines.

Try this, go into the email-order-items.php file in your themes Woocommerce > Emails folder and replace everything in that file with the paste here: http://pastebin.com/qZrhCdKt

That should do it because we are just adding a line break to the url's. If you continue to have problems with it you can shoot me an email at contact[at]designloud[dot]com and I will be more than happy to help you get it sorted out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.