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

Validation: wildcard symbol to match any one level of the array not working correctly #5286

Closed
jahmedk opened this issue Nov 5, 2021 · 3 comments

Comments

@jahmedk
Copy link

jahmedk commented Nov 5, 2021

PHP Version

7.3

CodeIgniter4 Version

4.0.5

Which operating systems have you tested for this bug?

Windows

Which server did you use?

apache

Database

mysql

What happened?

One level array validating just 0 index but it's not working on multiple records.

Steps to Reproduce

image
image

image
image

Expected Output

$validation->run($aVars) must be false if array contain invalid data

Anything else?

No response

@jahmedk jahmedk added the bug Verified issues on the current code behavior or pull requests that will fix them label Nov 5, 2021
@kenjis
Copy link
Member

kenjis commented Nov 5, 2021

Can't reproduce on the latest develop branch.
It seems it has been fixed.

tests/system/Validation/ValidationTest.php:

    public function test_5286(): void
    {
        $rules = [
            'arl1.*.id' => 'required|regex_match[/^[0-9]+$/]',
            'arl1.*.alpha' => 'required|regex_match[/^[?a-zA-Z ]+$/]',
        ];
        $data = [
            'arl1' => [
                [
                    'id' => 101,
                    'alpha' => 'Simple String',
                ],
                [
                    'id' => '#10003',
                    'alpha' => 'Simple & Symbol',
                ],
            ],
        ];
        $actual = $this->validation->setRules($rules)->run($data);
        d($actual);
        dd($this->validation->getErrors());
    }
$ ./phpunit tests/system/Validation/ValidationTest.php --filter=test_5286
PHPUnit 9.5.10 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.0.12
Configuration: /Users/kenji/work/codeigniter/CodeIgniter4/phpunit.xml


┌─────────────────────────────────────────────────────────────────────────────────────────────────┐
│ $actual                                                                                         │
└─────────────────────────────────────────────────────────────────────────────────────────────────┘
boolean false
═══════════════════════════════════════════════════════════════════════════════════════════════════
Called from <ROOT>/tests/system/Validation/ValidationTest.php:1032 [d()]

┌─────────────────────────────────────────────────────────────────────────────────────────────────┐
│ $this->validation->getErrors()                                                                  │
└─────────────────────────────────────────────────────────────────────────────────────────────────┘
array (2) [
    'arl1.*.id' => string (49) "The arl1.*.id field is not in the correct format."
    'arl1.*.alpha' => string (52) "The arl1.*.alpha field is not in the correct format."
]
═══════════════════════════════════════════════════════════════════════════════════════════════════
Called from <ROOT>/tests/system/Validation/ValidationTest.php:1033 [dd()]

@kenjis kenjis changed the title wildcard symbol to match any one level of the array not working correctly Validattion: wildcard symbol to match any one level of the array not working correctly Nov 5, 2021
@kenjis kenjis changed the title Validattion: wildcard symbol to match any one level of the array not working correctly Validation: wildcard symbol to match any one level of the array not working correctly Nov 5, 2021
@kenjis
Copy link
Member

kenjis commented Nov 5, 2021

Duplicate of #4510
Fixed by #4606

@jahmedk Can you upgrade to v4.1.4?
This was fixed in v4.1.2.

@kenjis kenjis closed this as completed Nov 5, 2021
@kenjis kenjis removed the bug Verified issues on the current code behavior or pull requests that will fix them label Nov 5, 2021
@jahmedk
Copy link
Author

jahmedk commented Nov 5, 2021

Hi yes
Thanks @kenjis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants