views:

57

answers:

3

Hi All,

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?

Could you please tell me what is the issue?

+3  A: 
$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
Yes, you are right, I also tested. working as expected as shown in codespec above. Might be some server issue. Is so?
Asif Mulla
@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
@ 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
@Asif on `index.php` just to (right after the initial `<?php`) `echo "testing"; exit();` and you'll now for sure if that is the correct file to be working on or not. If it is, do try to see if you can get/output the correct URL's. Only after will you *hunt* inside Kohana. That just to be sure that all is working good.
Frankie
@ 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
@Asif sorry but I couldn't understand your last comment. Where are you at?
Frankie
@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
@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
@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
@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
+2  A: 

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
Well spotted. But that’s rather a comment.
Gumbo
A: 

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
I am using PHP.
Asif Mulla