From e1cc1493b052698320419d1f7d51d52240c39f60 Mon Sep 17 00:00:00 2001 From: Sam Maosa Date: Tue, 24 Oct 2023 06:52:26 +0300 Subject: [PATCH] Do 3 Round substitution to avoid infinite loops --- src/Helpers/Framework.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Helpers/Framework.php b/src/Helpers/Framework.php index d9303ba..0a255df 100644 --- a/src/Helpers/Framework.php +++ b/src/Helpers/Framework.php @@ -76,9 +76,16 @@ public function substitute(string $expression, array $substitutions = [], string $values = collect($substitutions)->values(); $replacement = Str::of($expression)->replace($keys->toArray(), $values->toArray())->toString(); - while (Str::of($replacement)->contains($keys)) { - $replacement = $this->substitute($replacement,$substitutions,$substitutionIdentifier); + // ROUND 2 + if (Str::of($replacement)->contains($keys)) { + $replacement = Str::of($replacement)->replace($keys->toArray(), $values->toArray())->toString(); } + + // ROUND 3 + if (Str::of($replacement)->contains($keys)) { + $replacement = Str::of($replacement)->replace($keys->toArray(), $values->toArray())->toString(); + } + return $replacement; }