LWP & UTF-8 part 2.

LWP & UTF-8 part 2.

am 19.06.2006 15:29:16 von podbelsky

Howdy.
In my previous mail i wrote about the issue with ua->get(); method and a decoded utf-8 content, which was solved by calling $ua->parse_head(0);
Thanks for the advice.

But now i've come to the point that HTML::Form can't produce an HTTP::Request object if it is being feed with a decoded utf-8 html code:
$res = $ua->get('http://some.document/in/utf-8.html');
@forms = HTML::Form->parse($res); # $res->decoded_content has the utf-8 flag on.
Everything goes fine, until i call:
$forms[0]->click('login');
which gives a bunch of 'Use of uninitialized value in substitution iterator at perl.5.8.8/site/lib/URI/_query.pm line 16.' errors while trying to create a request object.

line 16 of my _query.pm: $q =~ s/([^$URI::uric])/$URI::Escape::escapes{$1}/go;
So this module is trying to escape unicode chars using the hash:
for (0..255) {
$escapes{chr($_)} = sprintf("%%%02X", $_);
}

And i had to encode all input values in the form just before calling form's click method:
for my $input ($forms[0]->inputs())
{
$input->readonly(0);
$input->value(encode_utf8($input->value())) if defined $input->value();
}
$forms[0]->click('login'); # now it's okay.

Am i doing right or is there any other workaround?
Looks like HTTP::Form doesn't work with utf-8 content out of the box.

Sincerely yours, shalom ebanats.