SimonSimCity / Xamarin-CrossDownloadManager

A cross platform download manager for Xamarin
MIT License
149 stars 68 forks source link

[ERROR] Download Crash/Stop when URL have Spaces ou accented words (maybe have more problems) #95

Closed rafaelrmou closed 6 years ago

rafaelrmou commented 6 years ago

To help us fix your issue, please provide the information in the below template.

Note: If you want to save time, please create a fork, reproduce the bug in the sample projects and add a link to the repository here.

Steps to reproduce

  1. Try to download that file with the Sample project: https://chat.fidelitymobile.org:3355/ClientDocument/images (5).jpg

  2. Download will not executing

Expected behavior

Download file

Actual behavior

File not Download

Configuration

Platform:

Device:

large commented 6 years ago

Hi @rafaelrmou When you have spaces or other "special" characters in the link you must encode the link right. (subject)

Try using:

System.Net.WebUtility.UrlEncode("https://chat.fidelitymobile.org:3355/ClientDocument/images (5).jpg");

It will output a string like this: https://chat.fidelitymobile.org:3355/ClientDocument/images%20(5).jpg

Notice the [SPACE] changed to %20 and the download should work. Let me know if it still fails, works on my Android simulator.

rafaelrmou commented 6 years ago

When using that method i receive:

https%3A%2F%2Fchat.fidelitymobile.org%3A3355%2FClientDocument%2Fimages+(5).jpg

I think that want to be fixed on platform specific

SimonSimCity commented 6 years ago

@rafaelrmou how do you get to this address? No service should give you an address like this since it's an invalid url.

The RFC 1738 strictly states in 2.2. URL Character Encoding Issues that:

The space character is unsafe because [...]

All unsafe characters must always be encoded within a URL.

So, wherever you got this URL from, it's not conform to the RFC and will thereby not be supported by this package.

There is the method HttpUtility.UrlPathEncode(String url) which might help you. Anyways - you should check the source of the url you're getting here and see if you have any chance to get a valid URL from it. Use the parameter AbsoluteUri of your URL instance instead of the to-string method.

If you only get a string with these characters, I suggest you to create a Uri instance first. Here's an example:

new Uri("https://chat.fidelitymobile.org:3355/ClientDocument/images (5).jpg")).AbsoluteUri
// returns https://chat.fidelitymobile.org:3355/ClientDocument/images%20(5).jpg

If you want: