[BUG] PHP Client - ObjectSerializer::buildQuery flattens array params resulting invalid URL params (param=a&param=b vs param[]=a&param[]=b) #19233 (#19236)

* [BUG] PHP Client - ObjectSerializer::buildQuery flattens array params resulting invalid URL params (param=a&param=b vs param[]=a&param[]=b) #19233

* Added tests (replaced old provider data). This looks like a breaking change

* Fix space

---------

Co-authored-by: Serban Ghita <serban.ghita@virta.global>
This commit is contained in:
Şerban Ghiţă 2024-08-07 12:15:59 +03:00 committed by GitHub
parent edc60db531
commit 539aab05a7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 41 additions and 9 deletions

View File

@ -258,6 +258,11 @@ class ObjectSerializer
$value = $flattenArray($value, $paramName);
// https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#style-values
if ($openApiType === 'array' && $style === 'deepObject' && $explode) {
return $value;
}
if ($openApiType === 'object' && ($style === 'deepObject' || $explode)) {
return $value;
}

View File

@ -256,6 +256,11 @@ class ObjectSerializer
$value = $flattenArray($value, $paramName);
// https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#style-values
if ($openApiType === 'array' && $style === 'deepObject' && $explode) {
return $value;
}
if ($openApiType === 'object' && ($style === 'deepObject' || $explode)) {
return $value;
}
@ -463,7 +468,7 @@ class ObjectSerializer
// determine file name
if (
is_array($httpHeaders)
&& array_key_exists('Content-Disposition', $httpHeaders)
&& array_key_exists('Content-Disposition', $httpHeaders)
&& preg_match('/inline; filename=[\'"]?([^\'"\s]+)[\'"]?$/i', $httpHeaders['Content-Disposition'], $match)
) {
$filename = Configuration::getDefaultConfiguration()->getTempFolderPath() . DIRECTORY_SEPARATOR . self::sanitizeFilename($match[1]);

View File

@ -268,6 +268,11 @@ class ObjectSerializer
$value = $flattenArray($value, $paramName);
// https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#style-values
if ($openApiType === 'array' && $style === 'deepObject' && $explode) {
return $value;
}
if ($openApiType === 'object' && ($style === 'deepObject' || $explode)) {
return $value;
}

View File

@ -267,6 +267,11 @@ class ObjectSerializer
$value = $flattenArray($value, $paramName);
// https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#style-values
if ($openApiType === 'array' && $style === 'deepObject' && $explode) {
return $value;
}
if ($openApiType === 'object' && ($style === 'deepObject' || $explode)) {
return $value;
}

View File

@ -265,6 +265,11 @@ class ObjectSerializer
$value = $flattenArray($value, $paramName);
// https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#style-values
if ($openApiType === 'array' && $style === 'deepObject' && $explode) {
return $value;
}
if ($openApiType === 'object' && ($style === 'deepObject' || $explode)) {
return $value;
}
@ -472,7 +477,7 @@ class ObjectSerializer
// determine file name
if (
is_array($httpHeaders)
&& array_key_exists('Content-Disposition', $httpHeaders)
&& array_key_exists('Content-Disposition', $httpHeaders)
&& preg_match('/inline; filename=[\'"]?([^\'"\s]+)[\'"]?$/i', $httpHeaders['Content-Disposition'], $match)
) {
$filename = Configuration::getDefaultConfiguration()->getTempFolderPath() . DIRECTORY_SEPARATOR . self::sanitizeFilename($match[1]);

View File

@ -28,7 +28,7 @@ class ObjectSerializerTest extends TestCase
$this->assertSame("sun.gif", ObjectSerializer::sanitizeFilename("../sun.gif"));
$this->assertSame("sun.gif", ObjectSerializer::sanitizeFilename("/var/tmp/sun.gif"));
$this->assertSame("sun.gif", ObjectSerializer::sanitizeFilename("./sun.gif"));
$this->assertSame("sun", ObjectSerializer::sanitizeFilename("sun"));
$this->assertSame("sun.gif", ObjectSerializer::sanitizeFilename("..\sun.gif"));
$this->assertSame("sun.gif", ObjectSerializer::sanitizeFilename("\var\tmp\sun.gif"));
@ -62,7 +62,7 @@ class ObjectSerializerTest extends TestCase
* File Streams Provider
* @return array[]
*/
public function provideFileStreams(): array
public static function provideFileStreams(): array
{
return [
'File stream without headers' => [
@ -112,7 +112,7 @@ class ObjectSerializerTest extends TestCase
*
* @return string[][]
*/
public function provideTimestamps(): array
public static function provideTimestamps(): array
{
return [
'String from #7942' => [
@ -173,7 +173,7 @@ class ObjectSerializerTest extends TestCase
*
* @return array[]
*/
public function provideQueryParams(): array
public static function provideQueryParams(): array
{
$array = ['blue', 'black', 'brown'];
$object = ['R' => 100, 'G' => 200, 'B' => 150];
@ -300,10 +300,12 @@ class ObjectSerializerTest extends TestCase
'deepObject array, explode off, required true' => [
$array, 'color', 'array', 'deepObject', false, true, 'color=blue%2Cblack%2Cbrown',
],
// color=blue&color=black&color=brown
// color[0]=blue&color[1]=black&color[2]=brown
'deepObject array, explode on, required true' => [
$array, 'color', 'array', 'deepObject', true, true, 'color=blue&color=black&color=brown',
$array, 'color', 'array', 'deepObject', true, true, 'color%5B0%5D=blue&color%5B1%5D=black&color%5B2%5D=brown',
],
// color[R]=100&color[G]=200&color[B]=150
'deepObject object, explode off, required true' => [
$object, 'color', 'object', 'deepObject', false, true, 'color%5BR%5D=100&color%5BG%5D=200&color%5BB%5D=150',

View File

@ -265,6 +265,11 @@ class ObjectSerializer
$value = $flattenArray($value, $paramName);
// https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#style-values
if ($openApiType === 'array' && $style === 'deepObject' && $explode) {
return $value;
}
if ($openApiType === 'object' && ($style === 'deepObject' || $explode)) {
return $value;
}
@ -472,7 +477,7 @@ class ObjectSerializer
// determine file name
if (
is_array($httpHeaders)
&& array_key_exists('Content-Disposition', $httpHeaders)
&& array_key_exists('Content-Disposition', $httpHeaders)
&& preg_match('/inline; filename=[\'"]?([^\'"\s]+)[\'"]?$/i', $httpHeaders['Content-Disposition'], $match)
) {
$filename = Configuration::getDefaultConfiguration()->getTempFolderPath() . DIRECTORY_SEPARATOR . self::sanitizeFilename($match[1]);