Loading lib/Travel/Status/DE/HAFAS.pm +9 −3 Original line number Diff line number Diff line Loading @@ -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); Loading t/30-invalid-xml.t +14 −3 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -18,4 +18,15 @@ my $status = Travel::Status::DE::HAFAS->new( 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' ); Loading
lib/Travel/Status/DE/HAFAS.pm +9 −3 Original line number Diff line number Diff line Loading @@ -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); Loading
t/30-invalid-xml.t +14 −3 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -18,4 +18,15 @@ my $status = Travel::Status::DE::HAFAS->new( 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' );