From 074790a7b92538c548491c2b5130a1e5a0df6597 Mon Sep 17 00:00:00 2001 From: Joseph Bielawski Date: Tue, 3 Oct 2023 12:00:52 +0200 Subject: [PATCH] Prevent fatal error when passing empty string to `\DOMDocument` (#500) * Prevent fatal error when passing empty string to `\DOMDocument` * Skip empty string in json & uuid checks --- .../src/Flow/ETL/Row/Factory/NativeEntryFactory.php | 12 ++++++++++++ .../Unit/Row/Factory/NativeEntryFactoryTest.php | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/src/core/etl/src/Flow/ETL/Row/Factory/NativeEntryFactory.php b/src/core/etl/src/Flow/ETL/Row/Factory/NativeEntryFactory.php index 7d2e1c01c..545447259 100644 --- a/src/core/etl/src/Flow/ETL/Row/Factory/NativeEntryFactory.php +++ b/src/core/etl/src/Flow/ETL/Row/Factory/NativeEntryFactory.php @@ -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) { @@ -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); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Factory/NativeEntryFactoryTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Factory/NativeEntryFactoryTest.php index 584e22284..b3ae96fc0 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Factory/NativeEntryFactoryTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Factory/NativeEntryFactoryTest.php @@ -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(