Skip to content

Commit

Permalink
Skip JSON & XML checks for string that doesn't look as this type of data
Browse files Browse the repository at this point in the history
  • Loading branch information
stloyd committed Oct 16, 2023
1 parent 841a277 commit 4ece323
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/core/etl/src/Flow/ETL/Row/Factory/NativeEntryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,17 @@ public function create(string $entryName, mixed $value) : Entry

if (\is_string($value)) {
if ('' !== $value) {
if ($this->isJson($value)) {
$trimmedValue = \trim($value);

if ($this->isJson($trimmedValue)) {
return Row\Entry\JsonEntry::fromJsonString($entryName, $value);
}

if ($this->isUuid($value)) {
if ($this->isUuid($trimmedValue)) {
return new Row\Entry\UuidEntry($entryName, Entry\Type\Uuid::fromString($value));
}

if ($this->isXML($value)) {
if ($this->isXML($trimmedValue)) {
return new Entry\XMLEntry($entryName, $value);
}
}
Expand Down Expand Up @@ -304,6 +306,10 @@ private function getClass(object $object) : string

private function isJson(string $string) : bool
{
if ('{' !== $string[0] && '[' !== $string[0]) {
return false;
}

if (
(!\str_starts_with($string, '{') || !\str_ends_with($string, '}'))
&&
Expand All @@ -330,6 +336,10 @@ private function isUuid(string $string) : bool

private function isXML(string $string) : bool
{
if ('<' !== $string[0]) {
return false;
}

if (\preg_match('/<(.+?)>(.+?)<\/(.+?)>/', $string) === 1) {
try {
\libxml_use_internal_errors(true);
Expand Down

0 comments on commit 4ece323

Please sign in to comment.