Skip to content

[Bug][Fortress] YAML validator with no attributes passes null parameter, causes argument type error at runtime #1250

@StrykeSlammerII

Description

@StrykeSlammerII

Chat discussion at https://chat.userfrosting.com/channel/support?msg=4x7WkcL72ehSs9WXq

YAML validators with 0 attributes cause the error UserFrosting\Fortress\Adapter\JqueryValidationAdapter::transformValidator(): Argument #3 ($validator) must be of type array, null given when the page is loaded.

JqueryValidationArrayAdapter line 70 calls transformValidator(), line 107 in the same class.

example YAML:

species:
    validators:
        required:

is equivalent to JSON

[
  'species' => [
    'validators' => [
      'required' => null
    ]
  ]
]

Spotted in UF5.0, still exists in 5.1

Docs do not (yet) address this edge case. Is it more correct to allow validators with no attributes, or to require that all validators have at least one attribute? 'label' or 'message' attributes seem applicable for most use cases.

In 5.1, $transformed = match ($validatorName) { block does not pass $validator to every option, so there may be room to allow it to be null.
Then perhaps escape it with $validator = $validator ?? array() at beginning of method?
[whatever the correct syntax would be for that ?? operator]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    In Progress

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions