2

My Browser shows URL with file name as

http://www.example.com/pdf/204177_20090604_Chloorhexidine_DCB_oogdruppels_0%2C1%25.pdf

Actual File name is 204160_20090604_Atropine_DCB_oogdruppels_0,5%.pdf

After urldecode, it gives wrong file name as http://www.example.com/pdf/204177_20090604_Chloorhexidine_DCB_oogdruppels_0,1%.pdf

Update:

Initially I thought that its problem of URL Decode, but files like name 204153_20090605_Aluminiumacetotartraat_DCB_oordruppels_1,2%.pdf while rendering in browser throws Bad request. I am using Kohana 3 framwork. Is it related with server?

hakre
  • 193,403
  • 52
  • 435
  • 836
Asif Mulla
  • 1,652
  • 2
  • 22
  • 32

3 Answers3

4
$url = 'http://204160_20090604_Atropine_DCB_oogdruppels_0,5%.pdf';
$encode = urlencode($url);
$decode = urldecode($encode);

echo $url."<br />";
echo $encode."<br />";
echo $decode."<br />";

// outputs
http://204160_20090604_Atropine_DCB_oogdruppels_0,5%.pdf
http%3A%2F%2F204160_20090604_Atropine_DCB_oogdruppels_0%2C5%25.pdf
http://204160_20090604_Atropine_DCB_oogdruppels_0,5%.pdf

All ok. You're error is somewhere else.

Frankie
  • 24,627
  • 10
  • 79
  • 121
  • Yes, you are right, I also tested. working as expected as shown in codespec above. Might be some server issue. Is so? – Asif Mulla Oct 21 '10 at 13:15
  • @Asif by your description I would probably say that it has something to do with the way Kohana treats URL's. I can't be sure because I've never used it but CI (Kohana's based in CI) has its tweaks. You should probably debug on the main `index.php` file before controllers and cleaners get called. – Frankie Oct 21 '10 at 17:38
  • @ Frankie: I tried to debug index.php. But after clicking link,either request is not going at index.php or its request handler class. Could you please give me some reference related to CI where we can tweak the request? – Asif Mulla Oct 22 '10 at 05:42
  • @Asif on `index.php` just to (right after the initial ` – Frankie Oct 22 '10 at 11:58
  • @ Frankie: its not going upto the Kohana index only. Prior that only it throws bad request. So far i found that we have to right htaccess rule to escape % sign – Asif Mulla Oct 22 '10 at 12:10
  • @Asif sorry but I couldn't understand your last comment. Where are you at? – Frankie Oct 22 '10 at 13:42
  • @Frankie: Thanks for your help so far. I found that 400-Bad Request errors cannot be fixed in .htaccess, because these requests are rejected before the server executes any configuration files. The server is saying "This request is invalid, and I cannot process it at all" – Asif Mulla Oct 25 '10 at 06:44
  • @Frankie:You will not be able to use a literal "%" character in the filepath, because that character is reserved for escaping of all other characters in URLs. Because a URL may have to be multiply-escaped as it passes through various proxies and servers between the client and the end-server that will actually serve the request, the "%" character itself cannot be escaped. – Asif Mulla Oct 25 '10 at 06:45
  • @Asif, `%`'s are URL escaped as `%25`. As for the HTTP error code 400 that is new information and you probably should post a new question about it. – Frankie Oct 25 '10 at 10:52
  • @Frankie: Yes I have posted separate question once I got to know about this http://stackoverflow.com/questions/3988028/http-400-bad-request-while-downloading-file/3995657#3995657 – Asif Mulla Oct 25 '10 at 10:56
2

You are looking at two different files.

It's not possible to urlencode 204160_20090604_Atropine_DCB_oogdruppels_ into 204177_20090604_Chloorhexidine_DCB_oogdruppels_, encoding does not change alphabetical characters.

The error is most likely in the code that creates the file list and outputs the links; the mapping between link titles and filenames appears to be messed up.

Saul
  • 17,973
  • 8
  • 64
  • 88
0

this will give you exact file name m using c#

Server.UrlDecode("http://www.example.com/pdf/204160_20090604_Atropine_DCB_oogdruppels_0,5%25.pdf")

, (comma) is encoded as %2c % (percent) is encoded as %25 by browsers

if you use Request.Url it'll decode ,(comma) but not %(percent)

So Server.UrlDecode("xyz") decode all characters except %(percent), thats y there's "%25" in the above filename

FosterZ
  • 3,863
  • 6
  • 38
  • 62