From 427eb77fd9fc15630fb246c274cfb1fb83db07c4 Mon Sep 17 00:00:00 2001 From: sparkyx Date: Sat, 29 Nov 2025 09:01:53 +0100 Subject: [PATCH] XMLInvoice Check the type of XML document and throw an exception if invalid --- include/XMLDocument/xmlcreditnote_reader.class.php | 5 +++++ include/XMLDocument/xmlinvoice_reader.class.php | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/XMLDocument/xmlcreditnote_reader.class.php b/include/XMLDocument/xmlcreditnote_reader.class.php index 747df8fb6..f961191ba 100644 --- a/include/XMLDocument/xmlcreditnote_reader.class.php +++ b/include/XMLDocument/xmlcreditnote_reader.class.php @@ -35,6 +35,7 @@ namespace Noalyss\XMLDocument; * Exception code : * - 55 : XML Invalid * - 62 : filename don't exist + * - 140: not a credit note * Namespace standard (from XSD) * * Array @@ -135,6 +136,10 @@ class XMLCreditNote_Reader extends XML_Reader { $result = []; $node = $this->get_node("//cac:CreditNoteLine"); + if ($node == null ) + { + throw new \Exception ("XC140 invalide document",140); + } for ($e = 0; $e < $node->length; $e++) { $row = []; diff --git a/include/XMLDocument/xmlinvoice_reader.class.php b/include/XMLDocument/xmlinvoice_reader.class.php index fd1d346bb..b0e7f6349 100644 --- a/include/XMLDocument/xmlinvoice_reader.class.php +++ b/include/XMLDocument/xmlinvoice_reader.class.php @@ -34,6 +34,7 @@ namespace Noalyss\XMLDocument; * Exception code : * - 55 : XML Invalid * - 62 : filename don't exist + * - 143 : not an invoice * Namespace standard (from XSD) * * Array @@ -100,6 +101,12 @@ class XMLInvoice_Reader extends XML_Reader { $result = []; $node = $this->get_node("//cac:InvoiceLine"); + + // read Invoice + if ( $node == null ) + { + throw new \Exception ("XR143 unknow document",143); + } for ($e = 0; $e < $node->length; $e++) { $row = []; @@ -113,8 +120,8 @@ class XMLInvoice_Reader extends XML_Reader $row ['tva_percent'] = $this->get_node_value("//cac:InvoiceLine/cac:Item/cac:ClassifiedTaxCategory/cbc:Percent", $e); $result[] = $row; + return $result; } - return $result; } /** * @brief return the code of the document