Skip to content

Deep Name Collision #1668

@alganet

Description

@alganet

Affecting: 3.0 (unreleased)

Consider the following validator:

v::allOf(
    v::named('alpha', v::allOf(
        v::contains('quick'),
        v::contains('fox'),
    )),
    v::named('zeta', v::allOf(
        v::contains('lorem'),
        v::contains('ipsum'),
    ))->assert("foo bar";

As an user, I would expect to see the messages neatly grouped by their names. Since the asserted string does not contain any of the words, we should see them all.

Currently, this is the result:

  'allOf' => [
      0 => '"foo bar baz" must contain "quick"',
      1 => '"foo bar baz" must contain "fox"',
      2 => [
          0 => '"foo bar baz" must contain "lorem"',
          1 => '"foo bar baz" must contain "ipsum"',
      ],
  ],

This is not only missing the named groups, but it's also malformed, with grouping inconsistent with the structure of the validators themselves.

What I expected is something like:

  '__root__' => '"foo bar baz" must pass all the rules',
  0 => [
      '__root__' => 'alpha must pass all the rules',
      0 => '"foo bar baz" must contain "quick"',
      1 => '"foo bar baz" must contain "fox"',
  ],
  1 => [
      '__root__' => 'zeta must pass all the rules',
      0 => '"foo bar baz" must contain "lorem"',
      1 => '"foo bar baz" must contain "ipsum"',
  ],

This is also consistent with the same unnamed version (which would produce identical __root__ entries, thus preventing it from using as the key.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions