Fix ObjectSerializer::isEmptyValue to not consider "0" as "" (#19472)

This commit is contained in:
Sobhan Sharifi 2024-09-02 11:03:36 +03:00 committed by GitHub
parent 5b96e85fd5
commit 0643f526af
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 27 additions and 0 deletions

View File

@ -188,6 +188,9 @@ class ObjectSerializer
# For boolean values, '' is considered empty
'bool','boolean' => !in_array($value, [false, 0], true),
# For string values, '' is considered empty.
'string' => $value === '',
# For all the other types, any value at this point can be considered empty.
default => true
};

View File

@ -185,6 +185,10 @@ class ObjectSerializer
case 'boolean':
return !in_array($value, [false, 0], true);
# For string values, '' is considered empty.
case 'string':
return $value === '';
# For all the other types, any value at this point can be considered empty.
default:
return true;

View File

@ -198,6 +198,9 @@ class ObjectSerializer
# For boolean values, '' is considered empty
'bool','boolean' => !in_array($value, [false, 0], true),
# For string values, '' is considered empty.
'string' => $value === '',
# For all the other types, any value at this point can be considered empty.
default => true
};

View File

@ -198,6 +198,9 @@ class ObjectSerializer
# For boolean values, '' is considered empty
'bool','boolean' => !in_array($value, [false, 0], true),
# For string values, '' is considered empty.
'string' => $value === '',
# For all the other types, any value at this point can be considered empty.
default => true
};

View File

@ -197,6 +197,9 @@ class ObjectSerializer
# For boolean values, '' is considered empty
'bool','boolean' => !in_array($value, [false, 0], true),
# For string values, '' is considered empty.
'string' => $value === '',
# For all the other types, any value at this point can be considered empty.
default => true
};

View File

@ -194,6 +194,10 @@ class ObjectSerializer
case 'boolean':
return !in_array($value, [false, 0], true);
# For string values, '' is considered empty.
case 'string':
return $value === '';
# For all the other types, any value at this point can be considered empty.
default:
return true;

View File

@ -430,6 +430,9 @@ class ObjectSerializerTest extends TestCase
'form 0 bool, explode on, required false' => [
0, 'field', 'bool', 'form', true, false, 'field=0',
],
'form string "0", explode on, required true' => [
'0', 'field', 'string', 'form', true, true, 'field=0',
],
];
}

View File

@ -194,6 +194,10 @@ class ObjectSerializer
case 'boolean':
return !in_array($value, [false, 0], true);
# For string values, '' is considered empty.
case 'string':
return $value === '';
# For all the other types, any value at this point can be considered empty.
default:
return true;