fix : nettoyer le buffer libxml et pin de contrat sur les listes multi-enfants

This commit is contained in:
2026-04-21 08:24:43 +02:00
parent 46f99a4243
commit e239f6fe58
2 changed files with 26 additions and 3 deletions

View File

@@ -35,9 +35,14 @@ final class ZipMessageDecoder
@unlink($tempFile);
}
$previous = libxml_use_internal_errors(true);
$simpleXml = simplexml_load_string($xml);
libxml_use_internal_errors($previous);
$previous = libxml_use_internal_errors(true);
try {
$simpleXml = simplexml_load_string($xml);
} finally {
libxml_clear_errors();
libxml_use_internal_errors($previous);
}
if (false === $simpleXml) {
throw new RuntimeException('ZipMessageDecoder: XML invalide dans l\'archive ZIP.');

View File

@@ -32,6 +32,24 @@ final class ZipMessageDecoderTest extends TestCase
self::assertSame('F', (string) $decoded->Bovins->Bovin->IdentiteBovin->Sexe);
}
public function testDecodeProducesArrayForMultiChildNodes(): void
{
$xml = '<?xml version="1.0" encoding="UTF-8"?>'
.'<MessageIpBNotifGetInventaire>'
.'<Bovins>'
.'<Bovin><IdentiteBovin><Sexe>F</Sexe></IdentiteBovin></Bovin>'
.'<Bovin><IdentiteBovin><Sexe>M</Sexe></IdentiteBovin></Bovin>'
.'</Bovins>'
.'</MessageIpBNotifGetInventaire>';
$decoded = new ZipMessageDecoder()->decode($this->makeZipBinary('message.xml', $xml));
self::assertIsArray($decoded->Bovins->Bovin);
self::assertCount(2, $decoded->Bovins->Bovin);
self::assertSame('F', (string) $decoded->Bovins->Bovin[0]->IdentiteBovin->Sexe);
self::assertSame('M', (string) $decoded->Bovins->Bovin[1]->IdentiteBovin->Sexe);
}
public function testDecodeThrowsOnEmptyBinary(): void
{
$this->expectException(RuntimeException::class);