From 07973dee2d9729c28cb12ede1875376726ae1374 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Fri, 8 May 2026 14:19:51 +0530 Subject: [PATCH] Refactor URL parameter replacement logic in OpenAPI3 and Swagger2 to ensure accurate matching of path parameters by checking for trailing characters. --- .../SDK/Specification/Format/OpenAPI3.php | 15 ++++++++++++++- .../SDK/Specification/Format/Swagger2.php | 15 ++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) 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; + } } }