Skip to content

Commit

Permalink
Do 3 Round substitution to avoid infinite loops
Browse files Browse the repository at this point in the history
  • Loading branch information
coolsam726 committed Oct 24, 2023
1 parent 5b407c9 commit e1cc149
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Helpers/Framework.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit e1cc149

Please sign in to comment.