From 5cfaa0807dcf76b02ddb01ba26040d8d597ef418 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Fri, 8 May 2026 14:08:27 +0530 Subject: [PATCH] Refactor URL parameter matching in OpenAPI3 and Swagger2 to improve path parameter detection by checking for trailing characters. --- src/Appwrite/SDK/Specification/Format/OpenAPI3.php | 14 +++++++++++--- src/Appwrite/SDK/Specification/Format/Swagger2.php | 14 +++++++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/Appwrite/SDK/Specification/Format/OpenAPI3.php b/src/Appwrite/SDK/Specification/Format/OpenAPI3.php index b47d716737..c91945fe2b 100644 --- a/src/Appwrite/SDK/Specification/Format/OpenAPI3.php +++ b/src/Appwrite/SDK/Specification/Format/OpenAPI3.php @@ -758,9 +758,17 @@ class OpenAPI3 extends Format $pathAliases = [$name, ...($param['aliases'] ?? [])]; $isPathParam = false; foreach ($pathAliases as $pathAlias) { - if (false !== \strpos($url, ':' . $pathAlias)) { - $isPathParam = true; - break; + $pathNeedle = ':' . $pathAlias; + $offset = 0; + + while (false !== ($position = \strpos($url, $pathNeedle, $offset))) { + $nextChar = $url[$position + \strlen($pathNeedle)] ?? ''; + if ($nextChar === '' || $nextChar === '/') { + $isPathParam = true; + break 2; + } + + $offset = $position + 1; } } diff --git a/src/Appwrite/SDK/Specification/Format/Swagger2.php b/src/Appwrite/SDK/Specification/Format/Swagger2.php index 61fa2919c9..be0f430a7a 100644 --- a/src/Appwrite/SDK/Specification/Format/Swagger2.php +++ b/src/Appwrite/SDK/Specification/Format/Swagger2.php @@ -725,9 +725,17 @@ class Swagger2 extends Format $pathAliases = [$name, ...($param['aliases'] ?? [])]; $isPathParam = false; foreach ($pathAliases as $pathAlias) { - if (\str_contains($url, ':' . $pathAlias)) { - $isPathParam = true; - break; + $pathNeedle = ':' . $pathAlias; + $offset = 0; + + while (false !== ($position = \strpos($url, $pathNeedle, $offset))) { + $nextChar = $url[$position + \strlen($pathNeedle)] ?? ''; + if ($nextChar === '' || $nextChar === '/') { + $isPathParam = true; + break 2; + } + + $offset = $position + 1; } }