[Israel.pm] Hebrew with CGI

Shlomi Fish shlomif at iglu.org.il
Tue Jun 28 02:29:17 PDT 2005


On Tuesday 28 June 2005 11:04, Guy Malachi wrote:
> I can't seem to do anything in the script once I pass it %uANYTHING in the
> URL. I even changed my script to be
> 	print "Content-type:text/html\n\n";
> 	use Data::Dumper;
> 	print "<pre>";
> 	print Dumper \%ENV;
> But once there is %u in the URL I get an error.
> I played around with it a bit and it seems that if there is a % in the URL
> that is not followed immediately by two digits then my script fails.
>
> Any ideas?

Well, it works perfectly for me. The following CGI script:

<<<<<<<
#!/usr/bin/perl

print "Content-type:text/html\n\n";
use Data::Dumper;
print "<pre>";
print Dumper \%ENV;
>>>>>>

And the following client:

<<<<<<<
#!/usr/bin/perl

use warnings;
use strict;

use IO::All;

my $f = io("localhost:80");

$f->print(<<"EOF"
GET /cgi-bin/shlomi/unicode-char.pl?str=\%u0509 HTTP/1.0\r
User-Agent: Wget/1.9.1\r
Host: localhost\r
Accept: */*\r
Connection: Keep-Alive

EOF
);

print $f->slurp();

>>>>>>

Work as expected. Even this one does:

<<<<<<<
#!/usr/bin/perl

use CGI;

my $cgi = CGI->new();

print $cgi->header();

print "<html><body>Hi there! " . $cgi->param("str") . "</body></html>\n";
>>>>>>>

So I guess it's a web-server bug or misconfiguration.

I'm using perl-5.8.6-6.1.102mdk on Mandriva 2005 LE, Apache 2 2.0.53-9mdk.

It's probably running as CGI and I haven't checked with mod_perl yet.

Regards,

	Shlomi Fish

> -----Original Message-----
> From: perl-bounces at perl.org.il [mailto:perl-bounces at perl.org.il] On Behalf
> Of Omer Zak Sent: Tuesday, June 28, 2005 12:10 AM
> To: Perl in Israel
> Subject: RE: [Israel.pm] Hebrew with CGI
>
> 1. What does your server log say? (It should write something to the log
> whenever it responds with HTTP 500 error.)
> 2. Use a lower level module than CGI (or a callback function from CGI)
> and add a function, which translates the URL string from %uXXXX based
> one into %hh%hh based?
>                                                            --- Omer
>
> On Tue, 2005-06-28 at 00:37 +0200, Guy Malachi wrote:
> > I can't really do that because the requests to my script come from
> > bookmarklets that people run on various sites. The Hebrew that is passed
> > is because the bookmarklet is run on a site that has a title in Hebrew.
> > Basically people have a link the looks like this:
> > <a
> > href="javascript:document.location.href='http://mysite.com/myscript.pl?st
> >r= '+encodeURIComponent(document.title)">send site</a>
> >
> > -----Original Message-----
> > From: perl-bounces at perl.org.il [mailto:perl-bounces at perl.org.il] On
> > Behalf Of Omer Zak Sent: Monday, June 27, 2005 10:53 PM
> > To: Perl in Israel
> > Subject: Re: [Israel.pm] Hebrew with CGI
> >
> > Try %D7%99 (obtained by encoding the string first to UTF-8 and then
> > using the appropriate JavaScript encoding function).
> >                                                        --- Omer
> >
> > On Mon, 2005-06-27 at 23:17 +0200, Guy Malachi wrote:
> > > Hey guys,
> > > I am trying to call my CGI script with a url like this:
> > > http://mysite.com/myscript.pl?str=%u05D9
> > >
> > > As soon as my script gets a "%u" in the URL it crashes (I get an HTTP
> > > 500 error). Anybody have an idea how I can make this work?
> > >
> > > BTW: the %u05D9 is created by encoding a string that has Hebrew
> > > characters in it by using JavaScript's encodeURIComponent.
> > >
> > > My script is a simple CGI script that looks something like this:
> > >
> > > use CGI;
> > > my $q=new CGI;
> > > print $q->header();
> > >
> > > my $str=$q->param('str');
> > > #do something with $str

-- 

---------------------------------------------------------------------
Shlomi Fish      shlomif at iglu.org.il
Homepage:        http://www.shlomifish.org/

Tcl is LISP on drugs. Using strings instead of S-expressions for closures
is Evil with one of those gigantic E's you can find at the beginning of 
paragraphs.



More information about the Perl mailing list