Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Travel-Status-DE-HAFAS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
derf
Travel-Status-DE-HAFAS
Commits
4e5d250b
Commit
4e5d250b
authored
4 years ago
by
Birte Kristina Friesel
Browse files
Options
Downloads
Patches
Plain Diff
Do not croak when receiving invalid XML
parent
220b3bf3
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/Travel/Status/DE/HAFAS.pm
+9
-3
9 additions, 3 deletions
lib/Travel/Status/DE/HAFAS.pm
t/30-invalid-xml.t
+14
-3
14 additions, 3 deletions
t/30-invalid-xml.t
with
23 additions
and
6 deletions
lib/Travel/Status/DE/HAFAS.pm
+
9
−
3
View file @
4e5d250b
...
...
@@ -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
);
...
...
This diff is collapsed.
Click to expand it.
t/30-invalid-xml.t
+
14
−
3
View file @
4e5d250b
...
...
@@ -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
'
);
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment