Skip to content

Commit

Permalink
Version 2.12.2
Browse files Browse the repository at this point in the history
  • Loading branch information
eclipxe13 committed Sep 24, 2019
2 parents 7726eff + 7f40173 commit 62a7ad3
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

# Do not put this files on a distribution package
/tests/ export-ignore
/.appveyor.xml export-ignore
/.appveyor.yml export-ignore
/.codeclimate.yml export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
Expand Down
2 changes: 0 additions & 2 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ tools:
build:
nodes:
analysis:
project_setup:
override: true
tests:
override:
- php-scrutinizer-run --enable-security-analysis
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
"keywords": ["cfdi", "cfdi33", "mexico", "electronic invoice"],
"homepage": "https://github.com/eclipxe13/CfdiUtils",
"support": {
"source": "https://github.com/eclipxe13/CfdiUtils",
"issues": "https://github.com/eclipxe13/CfdiUtils/issues",
"docs": "https://cfdiutils.readthedocs.io/"
"docs": "https://cfdiutils.readthedocs.io/",
"chat": "https://discord.gg/aFGYXvX"
},
"license": "MIT",
"authors": [
Expand Down
11 changes: 11 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@
- Change visibility of `CfdiUtils\Cleaner\Cleaner#removeIncompleteSchemaLocation()` to private.


## Version 2.12.2 2019-09-24

- When cannot load an Xml string include `LibXMLError` information into exception, like:
```text
Cannot create a DOM Document from xml string
XML Fatal [L: 1, C: 7]: Input is not proper UTF-8
```
- Include composer `support` sections `source` and `chat`
- Development: Exclude correct file `.appveyor.yml` (was `.appveyor.xml`)


## Version 2.12.1 2019-09-11

- Trigger E_USER_DEPRECATED on `CfdiUtils\Cleaner\Cleaner#removeIncompleteSchemaLocation()`
Expand Down
2 changes: 2 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ trabajar con CFDI y también para obtener su ayuda, todo lo que la comunidad pue
contribuir será bien apreciado. Tenemos una comunidad activa y dinámica, nos puedes
encontrar en el [canal #phpcfdi de discord][discord].

No olvides visitar <https://www.phpcfdi.com> donde contamos con muchas más librerías relacionadas con
CFDI y herramientas del SAT. Y próximamente el lugar donde publicaremos la versión `3.y.z`.

## Lectura de CFDI

Expand Down
6 changes: 3 additions & 3 deletions src/CfdiUtils/Internals/BaseConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function convert(string $input, int $frombase, int $tobase): string

$originalSequence = $this->sequence()->value();
if ('' === $input) {
$input = $originalSequence{0}; // use zero as input
$input = $originalSequence[0]; // use zero as input
}
$chars = substr($originalSequence, 0, $frombase);
if (! boolval(preg_match("/^[$chars]+$/", $input))) {
Expand All @@ -57,7 +57,7 @@ public function convert(string $input, int $frombase, int $tobase): string
$length = strlen($input);
$values = [];
for ($i = 0; $i < $length; $i++) {
$values[] = intval(stripos($originalSequence, $input{$i}));
$values[] = intval(stripos($originalSequence, $input[$i]));
}

$result = '';
Expand All @@ -76,7 +76,7 @@ public function convert(string $input, int $frombase, int $tobase): string
}
}
$length = $newlen;
$result = $originalSequence{$divide} . $result;
$result = $originalSequence[$divide] . $result;
} while ($newlen > 0);

return $result;
Expand Down
26 changes: 25 additions & 1 deletion src/CfdiUtils/Utils/Xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use DOMDocument;
use DOMElement;
use DOMNode;
use LibXMLError;

class Xml
{
Expand Down Expand Up @@ -50,11 +51,34 @@ public static function newDocumentContent(string $content): DOMDocument
$document = static::newDocument();
// this error silenced call is intentional, no need to alter libxml_use_internal_errors
if (false === @$document->loadXML($content)) {
throw new \UnexpectedValueException('Cannot create a DOM Document from xml string');
throw new \UnexpectedValueException(
trim('Cannot create a DOM Document from xml string' . PHP_EOL . static::castLibXmlLastErrorAsString())
);
}
return $document;
}

private static function castLibXmlLastErrorAsString(): string
{
$error = libxml_get_last_error();
if (! $error instanceof LibXMLError) {
return '';
}
$types = [
LIBXML_ERR_NONE => 'None',
LIBXML_ERR_WARNING => 'Warning',
LIBXML_ERR_ERROR => 'Error',
LIBXML_ERR_FATAL => 'Fatal',
];
return sprintf(
'XML %s [L: %d, C: %d]: %s',
$types[$error->level] ?? 'Unknown',
$error->line,
$error->column,
$error->message
);
}

public static function isValidXmlName(string $name): bool
{
if ('' === $name) {
Expand Down
9 changes: 9 additions & 0 deletions tests/CfdiUtilsTests/Utils/XmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@

class XmlTest extends TestCase
{
public function testMethodNewDocumentContentWithInvalidXmlEncoding()
{
$invalidXml = utf8_decode('<e a="ñ"></e>'); // the ñ is a special character
$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage('Cannot create a DOM Document from xml string'
. PHP_EOL . 'XML Fatal [L: 1, C: 7]: Input is not proper UTF-8');
Xml::newDocumentContent($invalidXml);
}

public function testMethodDocumentElementWithoutRootElement()
{
$this->expectException(\UnexpectedValueException::class);
Expand Down

0 comments on commit 62a7ad3

Please sign in to comment.