Commit 4e5d250b authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

Do not croak when receiving invalid XML

parent 220b3bf3
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -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);
+14 −3
Original line number Diff line number Diff line
@@ -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;

@@ -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' );