Skip to content

Commit

Permalink
Normalizados saltos de línea al firmar
Browse files Browse the repository at this point in the history
- Actualizada clase FacturaeSigner
- Actualizados tests unitarios

> Relacionado con #175
  • Loading branch information
josemmo committed Dec 7, 2024
1 parent 5412dd0 commit c0bc067
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Common/FacturaeSigner.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ public function sign($xml) {
throw new RuntimeException('Invalid signing key material: failed to read private key');
}

// Normalize line breaks
$xml = str_replace("\r\n", "\n", $xml);
$xml = str_replace("\r", "\n", $xml);

// Extract root element
$openTagPosition = mb_strpos($xml, '<fe:Facturae ');
if ($openTagPosition === false) {
Expand Down
10 changes: 10 additions & 0 deletions tests/SignerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ public function testCanSignValidDocuments() {
}


public function testNormalizesLineBreaks() {
$xml = '<fe:Facturae xmlns:fe="http://www.facturae.es/Facturae/2014/v3.2.1/Facturae">' .
" <test>This contains\r\nWindows line breaks</test>\n" .
" <test>This contains\rclassic MacOS line breaks</test>\n" .
'</fe:Facturae>';
$signedXml = $this->getSigner()->sign($xml);
$this->assertStringNotContainsString("\r", $signedXml);
}


public function testCannotTimestampWithoutTsaDetails() {
$this->expectException(RuntimeException::class);
$signer = new FacturaeSigner();
Expand Down

0 comments on commit c0bc067

Please sign in to comment.