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: getValidated() missing data when double wildcard rule #9219

Closed
sanchawebo opened this issue Oct 9, 2024 · 3 comments · Fixed by #9220
Closed

Bug: getValidated() missing data when double wildcard rule #9219

sanchawebo opened this issue Oct 9, 2024 · 3 comments · Fixed by #9220
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@sanchawebo
Copy link
Contributor

PHP Version

8.3

CodeIgniter4 Version

4.5.5

CodeIgniter4 Installation Method

Composer (using codeigniter4/appstarter)

Which operating systems have you tested for this bug?

macOS, Linux

Which server did you use?

apache

Database

MySQL 5.7, 10.5.22-MariaDB

What happened?

When running validation in the controller and grabbing the validated data with $this->validator->getValidated(), the data for double wild card rules (eg dates.*.*) is missing.

Steps to Reproduce

Implement this controller (or the logic):

<?php

namespace App\Controllers\Back;

use App\Controllers\BaseController;

class TestController extends BaseController
{
    public function test()
    {
        $data = [
            'id'    => 1,
            'dates' => [
                23 => [
                    45 => '3.4.24',
                ],
            ],
        ];

        $this->validateData($data, [
            'id'        => 'required',
            'dates.*.*' => 'required',
        ]);

        $validated = $this->validator->getValidated();

        d($data, $validated);
    }
}

Expected Output

The validated data including in this case the date array.

Anything else?

I think the problem is that the validation rule ends in a double wildcard, because when i change the array and rules to this it works:

$data = [
    'id'    => 1,
    'dates' => [
        23 => [
            45 => [
                'date' => '3.4.24',
            ],
        ],
    ],
];

$this->validateData($data, [
    'id'             => 'required',
    'dates.*.*.date' => 'required',
]);

$validated = $this->validator->getValidated();

d($data, $validated);

Does CI4 not like rules ending with wildcards?

@sanchawebo sanchawebo added the bug Verified issues on the current code behavior or pull requests that will fix them label Oct 9, 2024
@ddevsr
Copy link
Collaborator

ddevsr commented Oct 11, 2024

@sanchawebo can you test on my PR #9220?

@sanchawebo
Copy link
Contributor Author

Earliest i can test this would be next week, sorry.

@sanchawebo
Copy link
Contributor Author

Tested your PR and it worked for my project. Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants