Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions api/contrib/genXML/genXML.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ function genXMLFe()
</Ubicacion>';
}

if ($emisorCodPaisTel != '' && $emisorTel != '' && $emisorTel >= EMISORNUMEROTELMIN && $emisorTel <= EMISORNUMEROTELMAX) {
if ($emisorCodPaisTel != '' && $emisorTel != '' && strlen($emisorTel) >= EMISORNUMEROTELMIN && strlen($emisorTel) <= EMISORNUMEROTELMAX) {

Copilot AI Mar 26, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The telefono inclusion check only validates length; it doesn’t trim or ensure the value is numeric. Per the v4.4 XSD, is xs:integer, so values like "2222-3333" or trailing spaces would now be emitted and cause schema validation failures. Consider normalizing (trim) and validating digits-only (e.g., ctype_digit after trim, or strip non-digits) before adding , and avoid calling strlen() twice by computing the length once.

Copilot uses AI. Check for mistakes.
$xmlString .= '
<Telefono>
<CodigoPais>' . $emisorCodPaisTel . '</CodigoPais>
Expand Down Expand Up @@ -1206,7 +1206,7 @@ function genXMLNC()
</Ubicacion>';
}

if ($emisorCodPaisTel != '' && $emisorTel != '' && $emisorTel >= EMISORNUMEROTELMIN && $emisorTel <= EMISORNUMEROTELMAX) {
if ($emisorCodPaisTel != '' && $emisorTel != '' && strlen($emisorTel) >= EMISORNUMEROTELMIN && strlen($emisorTel) <= EMISORNUMEROTELMAX) {

Copilot AI Mar 26, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR changes the emisor telefono validation/serialization not only for genXMLFe(), but also for genXMLNC/ND/TE/Fec/Fee. There are PHPUnit tests for genXMLFe(), but no coverage for the other generators, so regressions in those document types won’t be caught. Please add at least a minimal test (or a data-driven test) asserting that is included when emisor_tel is 8–20 digits for each affected generator.

Copilot uses AI. Check for mistakes.
$xmlString .= '
<Telefono>
<CodigoPais>' . $emisorCodPaisTel . '</CodigoPais>
Expand Down Expand Up @@ -2085,7 +2085,7 @@ function genXMLND()
</Ubicacion>';
}

if ($emisorCodPaisTel != '' && $emisorTel != '' && $emisorTel >= EMISORNUMEROTELMIN && $emisorTel <= EMISORNUMEROTELMAX) {
if ($emisorCodPaisTel != '' && $emisorTel != '' && strlen($emisorTel) >= EMISORNUMEROTELMIN && strlen($emisorTel) <= EMISORNUMEROTELMAX) {
$xmlString .= '
<Telefono>
<CodigoPais>' . $emisorCodPaisTel . '</CodigoPais>
Expand Down Expand Up @@ -2954,7 +2954,7 @@ function genXMLTE()
</Ubicacion>';
}

if ($emisorCodPaisTel != '' && $emisorTel != '' && $emisorTel >= EMISORNUMEROTELMIN && $emisorTel <= EMISORNUMEROTELMAX) {
if ($emisorCodPaisTel != '' && $emisorTel != '' && strlen($emisorTel) >= EMISORNUMEROTELMIN && strlen($emisorTel) <= EMISORNUMEROTELMAX) {
$xmlString .= '
<Telefono>
<CodigoPais>' . $emisorCodPaisTel . '</CodigoPais>
Expand Down Expand Up @@ -3883,7 +3883,7 @@ function genXMLFec()
<OtrasSenasExtranjero>' . $emisorOtrasSenasExtranjero . '</OtrasSenasExtranjero>';
}

if ($emisorCodPaisTel != '' && $emisorTel != '' && $emisorTel >= EMISORNUMEROTELMIN && $emisorTel <= EMISORNUMEROTELMAX) {
if ($emisorCodPaisTel != '' && $emisorTel != '' && strlen($emisorTel) >= EMISORNUMEROTELMIN && strlen($emisorTel) <= EMISORNUMEROTELMAX) {
$xmlString .= '
<Telefono>
<CodigoPais>' . $emisorCodPaisTel . '</CodigoPais>
Expand Down Expand Up @@ -4583,7 +4583,7 @@ function genXMLFee()
</Ubicacion>';
}

if ($emisorCodPaisTel != '' && $emisorTel != '' && $emisorTel >= EMISORNUMEROTELMIN && $emisorTel <= EMISORNUMEROTELMAX) {
if ($emisorCodPaisTel != '' && $emisorTel != '' && strlen($emisorTel) >= EMISORNUMEROTELMIN && strlen($emisorTel) <= EMISORNUMEROTELMAX) {
$xmlString .= '
<Telefono>
<CodigoPais>' . $emisorCodPaisTel . '</CodigoPais>
Expand Down
1 change: 1 addition & 0 deletions tests/api_contrib_genXML_FE.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ public function testGenXMLFeEmisor()
$this->assertEquals('01', (string)$xml->Emisor->Ubicacion->Distrito);
$this->assertEquals('Dirección de prueba', (string)$xml->Emisor->Ubicacion->OtrasSenas);
$this->assertEquals('empresa@example.com', (string)$xml->Emisor->CorreoElectronico);
$this->assertEquals('22223333', (string)$xml->Emisor->Telefono->NumTelefono);
}

public function testGenXMLFeDetalleServicio()
Expand Down
Loading