Refactor URL parameter matching in OpenAPI3 and Swagger2 to improve path parameter detection by checking for trailing characters.

This commit is contained in:
ArnabChatterjee20k
2026-05-08 14:08:27 +05:30
parent e181954dd1
commit 5cfaa0807d
2 changed files with 22 additions and 6 deletions
@@ -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;
}
}
@@ -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;
}
}