Skip to content

Type casting results in PHP error exception when object type is given #561

Closed
@OneEyedSpaceFish

Description

@OneEyedSpaceFish

Array validation for a given type, in this example integer fails with PHP internal error exception being thrown if a client supplies an array with an object element in it.

This seems to be the case for string type as well, so I'd assume that this is a more common issue across all types of constraints.

JSON body: [{}]

Integer example:
Schema

    "type": "array",
    "minItems": 1,
    "required": true,
    "uniqueItems": true,
    "additionalProperties": false,
    "items": {
        "type": "integer",
        "minimum": 1
    }

String Exception
PhpErrorException Exception; Code: internalError; Message: mb_detect_encoding() expects parameter 1 to be string, object given; File: .../justinrainbow/json-schema/src/JsonSchema/Constraints/StringConstraint.php; Line: 54;

Integer Exception
PhpErrorException Exception; Code: internalError; Message: Object of class stdClass could not be converted to int; File: .../justinrainbow/json-schema/src/JsonSchema/Constraints/NumberConstraint.php; Line: 38;

Versions affected: v5.2.8, v5.2.7, v5.2.6 (possibly more)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions