Skip to content

Commit

Permalink
Prevent fatal error when passing empty string to \DOMDocument (#500)
Browse files Browse the repository at this point in the history
* Prevent fatal error when passing empty string to `\DOMDocument`

* Skip empty string in json & uuid checks
  • Loading branch information
stloyd authored Oct 3, 2023
1 parent 72b95dd commit 074790a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/core/etl/src/Flow/ETL/Row/Factory/NativeEntryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@ private function getClass(object $object) : string

private function isJson(string $string) : bool
{
if ('' === $string) {
return false;
}

try {
return \is_array(\json_decode($string, true, self::JSON_DEPTH, JSON_THROW_ON_ERROR));
} catch (\Exception) {
Expand All @@ -307,11 +311,19 @@ private function isJson(string $string) : bool

private function isUuid(string $string) : bool
{
if ('' === $string) {
return false;
}

return 0 !== \preg_match(Entry\Type\Uuid::UUID_REGEXP, $string);
}

private function isXML(string $string) : bool
{
if ('' === $string) {
return false;
}

try {
\libxml_use_internal_errors(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ public function test_float_with_schema() : void
);
}

public function test_from_empty_string() : void
{
$this->assertEquals(
Entry::string('e', ''),
(new NativeEntryFactory())->create('e', '')
);
}

public function test_int() : void
{
$this->assertEquals(
Expand Down

0 comments on commit 074790a

Please sign in to comment.