feat: harden xml parsing to avoid uncaught errors
This commit is contained in:
1 parent
3849ae306c
commit
3234c78f0d
9 files changed
+229
-147
No files matched your search
@@ -44,15 +44,29 @@ class DocumentsParser
|
||||
|
||||
private function decode(Crawler $node): string
|
||||
{
|
||||
[, $pdfData] = explode(',', $node->text());
|
||||
if (0 === $node->count()) {
|
||||
throw new \InvalidArgumentException('Missing PDF node in document response.');
|
||||
}
|
||||
|
||||
$parts = explode(',', $node->text(), 2);
|
||||
if (2 !== count($parts)) {
|
||||
throw new \InvalidArgumentException('Invalid PDF payload in document response.');
|
||||
}
|
||||
|
||||
[, $pdfData] = $parts;
|
||||
|
||||
return base64_decode($pdfData);
|
||||
}
|
||||
|
||||
private function getFileInfo(Crawler $node): array
|
||||
{
|
||||
$pdfData = $this->decode($node->filterXPath('//pdf'));
|
||||
$filename = $node->filterXPath('//datei')->text();
|
||||
$pdfData = $this->decode($node->filterXPath('.//pdf'));
|
||||
$filenameNode = $node->filterXPath('.//datei');
|
||||
if (0 === $filenameNode->count()) {
|
||||
throw new \InvalidArgumentException('Missing filename node in document response.');
|
||||
}
|
||||
|
||||
$filename = $filenameNode->text();
|
||||
|
||||
return [$filename, $pdfData];
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user