Improve handling of broken data
Change-Id: I39afa2ad58ce39db3ce171876a0c3a5c540271df
diff --git a/lib/KorAP/XML/TEI.pm b/lib/KorAP/XML/TEI.pm
index 493fce5..aa8cd0f 100644
--- a/lib/KorAP/XML/TEI.pm
+++ b/lib/KorAP/XML/TEI.pm
@@ -115,11 +115,13 @@
CHECK:
+ return '' unless $html;
+
$html =~ s/<!--.*?-->//g; # remove all comments in actual line
# Remove comment spanning over several lines
# No closing comment found
- if ( index($html, '-->') == -1) {
+ if (index($html, '-->') == -1) {
# Opening comment found
$i = index($html, '<!--');
diff --git a/lib/KorAP/XML/TEI/Zipper.pm b/lib/KorAP/XML/TEI/Zipper.pm
index c479239..3f96370 100644
--- a/lib/KorAP/XML/TEI/Zipper.pm
+++ b/lib/KorAP/XML/TEI/Zipper.pm
@@ -3,6 +3,7 @@
use warnings;
use Log::Any qw($log);
use IO::Compress::Zip qw($ZipError :constants);
+use Scalar::Util 'blessed';
# man IO::Compress::Zip
# At present three compression methods are supported by IO::Compress::Zip, namely
@@ -69,6 +70,10 @@
# Close stream and reset zipper
sub close {
+ unless (blessed $_[0]->[1]) {
+ $log->fatal("No opened zip file to close");
+ return;
+ };
$_[0]->[1]->close;
@{$_[0]} = ($_[0]->[0]);
};