[Schema] Fix Implementation::fromArray rejecting falsy-but-valid name/version (#393)
* [Schema] Fix Implementation::fromArray rejecting falsy-but-valid name/version `empty()` treats the string "0" as empty, so a valid clientInfo/serverInfo with `"version": "0"` (or `"name": "0"`) was rejected with an InvalidArgumentException. During initialize this aborted request parsing and surfaced as a misleading "A valid session id is REQUIRED" error. Replace the `empty()` guards with explicit isset/is_string/empty-string checks so genuinely missing, non-string, and empty values are still rejected while "0" is accepted. Adds ImplementationTest covering the regression and the existing validation paths. Fixes #392 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * [Schema] Suppress PHPStan argument.type on invalid-input tests --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
12f4a78813
commit
206aa9da52
1 changed files with 179 additions and 2 deletions
|
|
@ -45,10 +45,10 @@ class Implementation implements \JsonSerializable
|
|||
*/
|
||||
public static function fromArray(array $data): self
|
||||
{
|
||||
if (empty($data['name']) || !\is_string($data['name'])) {
|
||||
if (!isset($data['name']) || !\is_string($data['name']) || '' === $data['name']) {
|
||||
throw new InvalidArgumentException('Invalid or missing "name" in Implementation data.');
|
||||
}
|
||||
if (empty($data['version']) || !\is_string($data['version'])) {
|
||||
if (!isset($data['version']) || !\is_string($data['version']) || '' === $data['version']) {
|
||||
throw new InvalidArgumentException('Invalid or missing "version" in Implementation data.');
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue