-
-
Notifications
You must be signed in to change notification settings - Fork 540
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[5.x] Prevents Recursive Fieldsets (#9539)
- Loading branch information
1 parent
17ec219
commit 54a0496
Showing
11 changed files
with
171 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Statamic\Exceptions; | ||
|
||
use Exception; | ||
use Spatie\Ignition\Contracts\BaseSolution; | ||
use Spatie\Ignition\Contracts\ProvidesSolution; | ||
use Spatie\Ignition\Contracts\Solution; | ||
|
||
class FieldsetRecursionException extends Exception implements ProvidesSolution | ||
{ | ||
public function __construct(private string $fieldset, private string $target) | ||
{ | ||
parent::__construct("Fieldset [$fieldset] is being imported recursively."); | ||
} | ||
|
||
public function getFieldset() | ||
{ | ||
return $this->fieldset; | ||
} | ||
|
||
public function getSolution(): Solution | ||
{ | ||
return BaseSolution::create('Avoid infinite recursion') | ||
->setSolutionDescription("The fieldset `$this->fieldset` is being imported into `$this->target`, however it has already been imported elsewhere. This is causing infinite recursion."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Statamic\Fields; | ||
|
||
use Illuminate\Support\Collection; | ||
use Statamic\Exceptions\FieldsetRecursionException; | ||
|
||
class FieldsetRecursionStack | ||
{ | ||
public function __construct(private Collection $stack) | ||
{ | ||
$this->stack = collect(); | ||
} | ||
|
||
public function push(string $import) | ||
{ | ||
if ($this->stack->contains($import)) { | ||
throw new FieldsetRecursionException($import, $this->stack->last()); | ||
} | ||
|
||
$this->stack->push($import); | ||
} | ||
|
||
public function pop() | ||
{ | ||
$this->stack->pop(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters