diff --git a/classes/phing/tasks/system/PhingTask.php b/classes/phing/tasks/system/PhingTask.php index d0b02c078b..6443215156 100644 --- a/classes/phing/tasks/system/PhingTask.php +++ b/classes/phing/tasks/system/PhingTask.php @@ -304,16 +304,34 @@ private function processFile(): void $this->newTarget = $this->newProject->getDefaultTarget(); } + $owningTargetName = $this->getOwningTarget()->getName(); // Are we trying to call the target in which we are defined? if ( $this->newProject->getBaseDir() == $this->project->getBaseDir() && $this->newProject->getProperty("phing.file") == $this->project->getProperty("phing.file") && $this->getOwningTarget() !== null - && $this->newTarget == $this->getOwningTarget()->getName() + && $this->newTarget == $owningTargetName ) { throw new BuildException("phing task calling its own parent target"); } + $targets = $this->getProject()->getTargets(); + $taskName = $this->getTaskName(); + array_walk( + $targets, + static function (Target $target) use ($owningTargetName, $taskName) { + if (in_array($owningTargetName, $target->getDependencies())) { + throw new BuildException( + sprintf( + "%s task calling a target that depends on its parent target '%s'.", + $taskName, + $owningTargetName + ) + ); + } + } + ); + $this->addReferences(); $this->newProject->executeTarget($this->newTarget); } catch (Exception $e) { diff --git a/test/classes/phing/tasks/condition/PhingTaskTest.php b/test/classes/phing/tasks/condition/PhingTaskTest.php index 5a122bb8db..5006bd0bdf 100644 --- a/test/classes/phing/tasks/condition/PhingTaskTest.php +++ b/test/classes/phing/tasks/condition/PhingTaskTest.php @@ -340,6 +340,14 @@ public function testOverrideWinsNoInheritAll() $this->expectLogContaining('test-property-override-no-inheritall-start', 'The value of test is 4'); } + /** + * Fail due to infinite recursion loop + */ + public function testInfiniteLoopViaDepends(): void + { + $this->expectBuildException('infinite-loop-via-depends', 'infinite loop'); + } + public function testMultiSameProperty(): void { $this->expectLogContaining('multi-same-property', 'prop is two');