Skip to content

Commit 7587104

Browse files
Merge pull request #103 from as3io/hotfix-0.3.18
Prevent infinite recursion of self-referencing embeds
2 parents 960f267 + 0aed023 commit 7587104

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

src/Metadata/Driver/YamlFileDriver.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,13 @@ protected function setEmbeds(Metadata\Interfaces\EmbedInterface $metadata, array
280280
$mapping['entity'] = null;
281281
}
282282

283-
$embedMeta = $this->loadMetadataForEmbed($mapping['entity']);
283+
if ($metadata instanceof Metadata\EmbedMetadata && $mapping['entity'] === $metadata->name) {
284+
// This embed meta is referencing itself as an embed property. As such, do not recreate.
285+
// This prevents infinite recursion.
286+
$embedMeta = $metadata;
287+
} else {
288+
$embedMeta = $this->loadMetadataForEmbed($mapping['entity']);
289+
}
284290
if (null === $embedMeta) {
285291
continue;
286292
}

src/Util/EntityUtility.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,10 @@ public function validateMetadataEmbeds(EmbedInterface $metadata, MetadataFactory
235235
{
236236
foreach ($metadata->getEmbeds() as $key => $embeddedProp) {
237237
$this->validateMetadataAttributes($embeddedProp->embedMeta, $mf);
238-
$this->validateMetadataEmbeds($embeddedProp->embedMeta, $mf);
238+
if ($metadata !== $embeddedProp->embedMeta) {
239+
// Only re-validate if the embedded prop reference isn't the same as the parent.
240+
$this->validateMetadataEmbeds($embeddedProp->embedMeta, $mf);
241+
}
239242
}
240243
return true;
241244
}

src/Version.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
*/
1010
class Version
1111
{
12-
const VERSION = '0.3.17';
13-
const ID = 3017;
12+
const VERSION = '0.3.18';
13+
const ID = 3018;
1414
const MAJOR = 0;
1515
const MINOR = 3;
16-
const PATCH = 17;
16+
const PATCH = 18;
1717
const EXTRA = '';
1818
}

0 commit comments

Comments
 (0)