Skip to content

Commit

Permalink
fix(sonar,danfe): atualiza geração de danfe de xml com caracteres inv…
Browse files Browse the repository at this point in the history
…álidos
  • Loading branch information
omathiasschulz committed Jun 21, 2024
1 parent 50c7804 commit 6346f2e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/NFe/Danfe.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,14 @@ public function __construct(
//se for passado o xml
if (!empty($this->xml)) {
$this->dom = new Dom();

// Remove caracteres não imprimíveis que podem quebrar a leitura do XML - @author Mathias Artur Schulz <[email protected]> (20-06-2024)
// Tabela de conversão ASCII, decimal, hexadecimal, octal e binário:
// https://www.ibm.com/docs/pt-br/aix/7.3?topic=adapters-ascii-decimal-hexadecimal-octal-binary-conversion-table
// A linha abaixo ignora qualquer caractere com valor ASCII entre 0 e 31 (caracteres não imprimíveis) ou o caractere com valor ASCII 127 (DEL)
// O modificador 'u' indica que estamos tratando o xml como UTF-8
$this->xml = preg_replace('/[\x00-\x1F\x7F]/u', '', $this->xml);

$this->dom->loadXML($this->xml);
$this->nfeProc = $this->dom->getElementsByTagName("nfeProc")->item(0);
$this->infNFe = $this->dom->getElementsByTagName("infNFe")->item(0);
Expand Down

0 comments on commit 6346f2e

Please sign in to comment.