Skip to content
Snippets Groups Projects
Commit 4e5d250b authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

Do not croak when receiving invalid XML

parent 220b3bf3
No related branches found
No related tags found
No related merge requests found
......@@ -180,9 +180,15 @@ sub new {
# errors in delay="...") when setting the language to dutch/italian.
# No, I don't know why.
$ref->{tree} = XML::LibXML->load_xml(
string => $ref->{raw_xml},
);
eval { $ref->{tree} = XML::LibXML->load_xml( string => $ref->{raw_xml} ) };
if ( my $err = $@ ) {
if ( $ref->{developer_mode} ) {
say $ref->{raw_xml};
}
$ref->{errstr} = "Backend returned invalid XML: $err";
return $ref;
}
if ( $ref->{developer_mode} ) {
say $ref->{tree}->toString(1);
......
......@@ -6,7 +6,7 @@ use 5.020;
use utf8;
use File::Slurp qw(read_file);
use Test::More tests => 1;
use Test::More tests => 2;
use Travel::Status::DE::HAFAS;
......@@ -15,7 +15,18 @@ my $xml = 'lol';
my $status = Travel::Status::DE::HAFAS->new(
service => 'DB',
station => 'Berlin Jannowitzbrücke',
xml => $xml
xml => $xml
);
is (scalar $status->results, 0, 'no results on invalid input');
is( scalar $status->results,
0, 'no results on valid XML with invalid HAFAS data' );
$xml = 'lol<';
$status = Travel::Status::DE::HAFAS->new(
service => 'DB',
station => 'Berlin Jannowitzbrücke',
xml => $xml
);
is( scalar $status->results, 0, 'no results on invalid XML' );
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment