diff --git a/src/Appwrite/SDK/Specification/Format/OpenAPI3.php b/src/Appwrite/SDK/Specification/Format/OpenAPI3.php index c91945fe2b..004be99c5b 100644 --- a/src/Appwrite/SDK/Specification/Format/OpenAPI3.php +++ b/src/Appwrite/SDK/Specification/Format/OpenAPI3.php @@ -814,7 +814,20 @@ class OpenAPI3 extends Format } foreach ($pathAliases as $pathAlias) { - $url = \str_replace(':' . $pathAlias, '{' . $name . '}', $url); + $pathNeedle = ':' . $pathAlias; + $replacement = '{' . $name . '}'; + $offset = 0; + + while (false !== ($position = \strpos($url, $pathNeedle, $offset))) { + $nextChar = $url[$position + \strlen($pathNeedle)] ?? ''; + if ($nextChar === '' || $nextChar === '/') { + $url = \substr($url, 0, $position) . $replacement . \substr($url, $position + \strlen($pathNeedle)); + $offset = $position + \strlen($replacement); + continue; + } + + $offset = $position + 1; + } } } diff --git a/src/Appwrite/SDK/Specification/Format/Swagger2.php b/src/Appwrite/SDK/Specification/Format/Swagger2.php index be0f430a7a..2d7965df6a 100644 --- a/src/Appwrite/SDK/Specification/Format/Swagger2.php +++ b/src/Appwrite/SDK/Specification/Format/Swagger2.php @@ -785,7 +785,20 @@ class Swagger2 extends Format } foreach ($pathAliases as $pathAlias) { - $url = \str_replace(':' . $pathAlias, '{' . $name . '}', $url); + $pathNeedle = ':' . $pathAlias; + $replacement = '{' . $name . '}'; + $offset = 0; + + while (false !== ($position = \strpos($url, $pathNeedle, $offset))) { + $nextChar = $url[$position + \strlen($pathNeedle)] ?? ''; + if ($nextChar === '' || $nextChar === '/') { + $url = \substr($url, 0, $position) . $replacement . \substr($url, $position + \strlen($pathNeedle)); + $offset = $position + \strlen($replacement); + continue; + } + + $offset = $position + 1; + } } }