You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "Vladimir S. Tikhonjuk" <vs...@vst.donetsk.ua> on 2006/09/12 07:32:03 UTC
Unescape URI
Hi all!
I have JavaScript function, which constructs html query like this:
var url =
'http://192.168.101.199/personal_account_search_ajax?key='+escape(key)+'&type='+type;
where variable 'key' is a value of form's line edit. When I enter there
non ASCII symbol, I get
url like this:
http://192.168.101.199/personal_account_search_ajax?key=%u043E&type=name.
Here is my personal_account_search_ajax handler:
package Promtelecom::PersonalAccountSearchAjax;
use strict;
use Apache2::Const -compile => qw( OK );
sub handler {
my $r = shift;
my $req = Apache2::Request->new( $r );
$req->content_type('text/xml; charset=KOI8-R');
my $search_key = $req->param('key');
my $search_type = $req->param('type');
my $archive_search = $req->param('archive_search');
return Apache2::Const::OK;
}
As I understand, I have to unescape URI here to get right value of
$req->param('key').
How to do it ?
Best regards,
Vladimir S. Tikhonjuk
Re: Unescape URI
Posted by Matias Alejo Garcia <ma...@confronte.com>.
On 9/12/06, Vladimir S. Tikhonjuk <vs...@vst.donetsk.ua> wrote:
>
> Hi all!
> I have JavaScript function, which constructs html query like this:
>
> var url =
> '
> http://192.168.101.199/personal_account_search_ajax?key='+escape(key)+'&type='+type
> ;
>
> where variable 'key' is a value of form's line edit. When I enter there
> non ASCII symbol, I get
> url like this:
> http://192.168.101.199/personal_account_search_ajax?key=%u043E&type=name.
>
> Here is my personal_account_search_ajax handler:
>
> package Promtelecom::PersonalAccountSearchAjax;
>
> use strict;
> use Apache2::Const -compile => qw( OK );
>
>
> sub handler {
> my $r = shift;
> my $req = Apache2::Request->new( $r );
> $req->content_type('text/xml; charset=KOI8-R');
>
> my $search_key = $req->param('key');
> my $search_type = $req->param('type');
> my $archive_search = $req->param('archive_search');
>
> return Apache2::Const::OK;
> }
>
> As I understand, I have to unescape URI here to get right value of
> $req->param('key').
> How to do it ?
You can try the following:
# For each value ...
# Decodes %XX characters
$val =~ s/%([0-9a-fA-F][0-9a-fA-F])/chr(hex($val))/eg;
# Decodes charset
eval {$newval=Encode::decode('utf8',$val,1)};
$newval=Encode::decode('KOI8-R',$val,1) if ($@);
We found problems with IE 6.0 & ajax request: sometimes it doesn't respect
page encoding. All our pages are UTF8, but some IE request use iso-8859-1.
We add the 'eval' to solve this.
I am a perl utf8 newbie, so it may be some misleading here.
--
http://confronte.com
Compará y comprá mejor