Subject: | XML::Fast does not expect decoded UTF-8 content |
In Net::DAVTalk, you readily Encode::decode() the response body:
# parse XML response {{{
my $Encoded = Encode::decode_utf8($ResponseContent);
my $Xml = xmlToHash($Encoded);
# Normalise XML
XML::Fast does not expect already decoded input and Perl throws a (fatal) warning.
If $ResponseContent contains actual UTF-8 characters (as in German text), this leads to the problem of not being able to parse responses.
Leaving out the call to "Encode::decode()" fixes the problem.
I've attached a test file that demonstrates the problem.
Thanks,
-max
Subject: | net-caldavtalk-utf8.t |
#!perl
use strict;
use warnings;
use charnames ':full';
use XML::Fast 'xml2hash';
use Devel::Peek;
use Encode ();
use Test::More tests => 3;
my $xml = <<"XML";
<?xml version="1.0" encoding="utf-8" ?>
<multistatus xmlns="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
<response>
<href>/davical/caldav.php/Corion/Max/71bff2bf-3995-425b-97c6-62449d38805c.ics</href>
<propstat>
<prop>
<C:calendar-data>BEGIN:VCALENDAR
VERSION:2.0
PRODID:+//IDN bitfire.at//DAVx5/2.5.4.1-ose ical4j/2.2.5
BEGIN:VEVENT
SUMMARY:Fahrt: Platz der Republik \342\236\235 Diesterwegstra\303\237 4
END:VEVENT
END:VCALENDAR
</C:calendar-data>
<getetag>"d258c735ba9041b1d2af9a3c2d951479"</getetag>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
</multistatus>
XML
warn $xml;
my $g = xml2hash( $xml );
#my $g1 = xml2hash( $xml, utf8decode => 1 );
my $xml_decoded = Encode::decode_utf8($xml);
my $h;
my $ok = eval {
$h = xml2hash( $xml_decoded );
1;
};
is $ok, 1, "We lived through xml2hash";
is $@, '', "No error message";
ok Encode::is_utf8($g->{multistatus}->{response}->{propstat}->{prop}->{'C:calendar-data'}),
"We still get UTF-8 decoded elements"
;
#use Data::Dumper;
#diag Dumper $g1->{multistatus}->{response}->{propstat}->{prop}->{'C:calendar-data'};
#Dump $g1->{multistatus}->{response}->{propstat}->{prop}->{'C:calendar-data'};