Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
StrykeSlammerII opened this issue Apr 14, 2024 · 1 comment
Milestone

Comments

@StrykeSlammerII
Copy link

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]

@lcharette
Copy link
Member

Then perhaps escape it with $validator = $validator ?? array() at beginning of method?

I like that idea. To avoid this issue in other, all Fortress methods currently tested agains't json schema should also be tested agains't YAML schemas.

@lcharette lcharette added this to the 5.1.x milestone Apr 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Not Started
Development

No branches or pull requests

2 participants