Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Validator] Exception handling with objects others than Constraint in Composite #21206

Copy link
Copy link
Closed
@SenseException

Description

@SenseException
Issue body actions
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version >= 2.7

This is a minor bug in Symfony\Component\Validator\Constraints\Composite in the Exception handling. While going through the nested constraints, a constraint that doesn't implement Symfony\Component\Validator\Constraint results in an exception:

foreach ($nestedConstraints as $constraint) {
    if (!$constraint instanceof Constraint) {
        throw new ConstraintDefinitionException(sprintf('The value %s is not an instance of Constraint in constraint %s', $constraint, get_class($this)));
    }

The wrong constraint will be added to the Exception message, but it is handled like a string and not an object.

Why is this an issue?

First, we expect objects to be used in a composite instead of scalars. Using the Symfony Framework, an abstraction in form of configuration files or annotations are common, that helps us to create the constraints for the validator, which is why a wrongly created custom constrain class and validator class is a more possible occurance.

What is the expected fix?

After the instance check, the case that $constraint can also be an object should be ensured and the class name be used in the Exception message.

I'll provide an PR for this soon.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.