Skip to content

Commit 71adf4f

Browse files
refactor: template inconsistency fix
1 parent 31ec25f commit 71adf4f

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

template/api.mustache

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,12 +420,32 @@ use \GuzzleHttp\Exception\GuzzleException;
420420
*/
421421
protected function buildQuery(array $params): string
422422
{
423-
// Let http_build_query do the heavy lifting:
424-
$qs = http_build_query($params, '', '&', PHP_QUERY_RFC3986);
423+
$sanitizedParams = $params;
425424
426-
// Normalize numeric indices to empty brackets: %5B0%5D= → %5B%5D=
427-
// (i.e., environment%5B0%5D=env1 → environment%5B%5D=env1)
428-
return preg_replace('/%5B\d+%5D=/', '%5B%5D=', $qs);
425+
foreach ($sanitizedParams as &$value) {
426+
if (is_array($value)) {
427+
array_walk_recursive($value, function (&$item) {
428+
if (null === $item) {
429+
$item = '';
430+
}
431+
});
432+
}
433+
}
434+
unset($value);
435+
436+
$qs = http_build_query($sanitizedParams, '', '&', PHP_QUERY_RFC3986);
437+
438+
if ('' === $qs || false === strpos($qs, '%5B')) {
439+
return $qs;
440+
}
441+
442+
$parts = explode('&', $qs);
443+
444+
foreach ($parts as $index => $part) {
445+
$parts[$index] = preg_replace('/([^%5B]+)%5B\d+%5D/', '$1%5B%5D', $part, 1);
446+
}
447+
448+
return implode('&', $parts);
429449
}
430450

431451
/**

0 commit comments

Comments
 (0)