mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Refactor URL parameter replacement logic in OpenAPI3 and Swagger2 to ensure accurate matching of path parameters by checking for trailing characters.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user