Skip to content

Commit 14d52ce

Browse files
authored
Merge pull request #12 from celli33/main
Codificación de los caracteres especiales
2 parents 584e08e + e0bc802 commit 14d52ce

File tree

6 files changed

+63
-6
lines changed

6 files changed

+63
-6
lines changed

src/Extractors/Comprobante32.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ public function format(array $values): string
5959
{
6060
return '?'
6161
. implode('&', [
62-
're=' . ($values['re'] ?? ''),
63-
'rr=' . ($values['rr'] ?? ''),
62+
're=' . (htmlentities($values['re'] ?? '', ENT_XML1)),
63+
'rr=' . (htmlentities($values['rr'] ?? '', ENT_XML1)),
6464
'tt=' . $this->formatTotal($values['tt'] ?? ''),
6565
'id=' . ($values['id'] ?? ''),
6666
]);

src/Extractors/Comprobante33.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ public function format(array $values): string
6262
return 'https://verificacfdi.facturaelectronica.sat.gob.mx/default.aspx?'
6363
. implode('&', [
6464
'id=' . ($values['id'] ?? ''),
65-
're=' . ($values['re'] ?? ''),
66-
'rr=' . ($values['rr'] ?? ''),
65+
're=' . (htmlentities($values['re'] ?? '', ENT_XML1)),
66+
'rr=' . (htmlentities($values['rr'] ?? '', ENT_XML1)),
6767
'tt=' . $this->formatTotal($values['tt'] ?? ''),
6868
'fe=' . ($values['fe'] ?? ''),
6969
]);

src/Extractors/Retenciones10.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ public function format(array $values): string
103103
}
104104
return '?'
105105
. implode('&', [
106-
're=' . ($values['re'] ?? ''),
107-
$receptorKey . '=' . ($values[$receptorKey] ?? ''),
106+
're=' . (htmlentities($values['re'] ?? '', ENT_XML1)),
107+
$receptorKey . '=' . (htmlentities($values[$receptorKey] ?? '', ENT_XML1)),
108108
'tt=' . $this->formatTotal($values['tt'] ?? ''),
109109
'id=' . ($values['id'] ?? ''),
110110
]);

tests/Unit/Extractors/Comprobante32Test.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,22 @@ public function testHowTotalMustBeFormatted(string $input, string $expectedForma
6767
$extractor = new Comprobante32();
6868
$this->assertSame($expectedFormat, $extractor->formatTotal($input));
6969
}
70+
71+
public function testFormatCfdi32RfcWithAmpersand(): void
72+
{
73+
$extractor = new Comprobante32();
74+
$expected32 = implode([
75+
'?re=Ñ&A010101AAA',
76+
'&rr=Ñ&A991231AA0',
77+
'&tt=0000001234.567800',
78+
'&id=CEE4BE01-ADFA-4DEB-8421-ADD60F0BEDAC',
79+
]);
80+
$parameters = [
81+
're' => 'Ñ&A010101AAA',
82+
'rr' => 'Ñ&A991231AA0',
83+
'tt' => '1234.5678',
84+
'id' => 'CEE4BE01-ADFA-4DEB-8421-ADD60F0BEDAC',
85+
];
86+
$this->assertSame($expected32, $extractor->format($parameters));
87+
}
7088
}

tests/Unit/Extractors/Comprobante33Test.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,25 @@ public function testHowTotalMustBeFormatted(string $input, string $expectedForma
6565
$extractor = new Comprobante33();
6666
$this->assertSame($expectedFormat, $extractor->formatTotal($input));
6767
}
68+
69+
public function testFormatCfdi33RfcWithAmpersand(): void
70+
{
71+
$extractor = new Comprobante33();
72+
$expected33 = implode([
73+
'https://verificacfdi.facturaelectronica.sat.gob.mx/default.aspx',
74+
'?id=CEE4BE01-ADFA-4DEB-8421-ADD60F0BEDAC',
75+
'&re=Ñ&A010101AAA',
76+
'&rr=Ñ&A991231AA0',
77+
'&tt=1234.5678',
78+
'&fe=23456789',
79+
]);
80+
$parameters = [
81+
'id' => 'CEE4BE01-ADFA-4DEB-8421-ADD60F0BEDAC',
82+
're' => 'Ñ&A010101AAA',
83+
'rr' => 'Ñ&A991231AA0',
84+
'tt' => '1234.5678',
85+
'fe' => '23456789',
86+
];
87+
$this->assertSame($expected33, $extractor->format($parameters));
88+
}
6889
}

tests/Unit/Extractors/Retenciones10Test.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,22 @@ public function testHowTotalMustBeFormatted(string $input, string $expectedForma
8888
$extractor = new Retenciones10();
8989
$this->assertSame($expectedFormat, $extractor->formatTotal($input));
9090
}
91+
92+
public function testFormatRetenciones10RfcWithAmpersand(): void
93+
{
94+
$extractor = new Retenciones10();
95+
$expectedRetenciones10 = implode([
96+
'?re=Ñ&A010101AAA',
97+
'&rr=Ñ&A991231AA0',
98+
'&tt=0002000000.000000',
99+
'&id=fc1b47b2-42f3-4ca2-8587-36e0a216c4d5',
100+
]);
101+
$parameters = [
102+
're' => 'Ñ&A010101AAA',
103+
'rr' => 'Ñ&A991231AA0',
104+
'tt' => '2000000.00',
105+
'id' => 'fc1b47b2-42f3-4ca2-8587-36e0a216c4d5',
106+
];
107+
$this->assertSame($expectedRetenciones10, $extractor->format($parameters));
108+
}
91109
}

0 commit comments

Comments
 (0)