perl - Why does using CGI::escape for my link URL make my browser take me to the wrong place? -


i using cgi escape method escape url href link tag. without escape() call link works fine in browser because smart enough translate spaces part of url.

my cgi script has

print $outhtml->a({href=>$outhtml->escape($wavurl)}, $outhtml->escapehtml($exportfilename));           

where $outhtml cgi object , wav url http://localhost/downloads/my file.mp3

with escape, output is:

<a href="http%3a%2f%2flocalhost%2fdownloads%2fmy%20file.mp3">my file</a> 

this looks okay me, chrome treats relative link, when click on or copy link address, appends localhost/cgi-bin, giving malformed address so:

http://localhost/cgi-bin/http%3a%2f%2flocalhost%2fdownloads%2fmy%20file.mp3 

i've tried without leading 'http://' in raw url well, , produces same bad behavior. tried using absolute url without hostname, /downloads/my file.mp3, has same behavior. i've tested on chrome , firefox , both have same result.

i tried uri::escape, did same thing.

what doing wrong?

you should escape values of cgi parameters not whole url. instance:

http://localhost/cgi-bin/get_file_by_url.pl?where=http%3a%2f%2flocalhost%2fdownloads%2fmy%20file.mp3 

the value of where has escaped. uri module helps you.

use uri; $myurl = uri->new('http://localhost/downloads/my file.mp3'); print $myurl->as_string, "\n"; # http://localhost/downloads/my%20file.mp3 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -