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

Error while using more than one parametrized validator #4

Closed
Averor opened this issue Mar 30, 2018 · 2 comments
Closed

Error while using more than one parametrized validator #4

Averor opened this issue Mar 30, 2018 · 2 comments

Comments

@Averor
Copy link
Contributor

Averor commented Mar 30, 2018

"A pattern can have a single main validator name and any number of sub-validators."

But, in below example

    $pattern = [
        'test' => ':string :min(1) :max(255)'
    ];

    $test = [
        'test' => 'test value'
    ];

two validators are created, string and min, the last having argument of

    1) :max(255

that means erroneous behavior.

Looking into

\PASVL\Pattern\Pattern::parse

method, and regexp used to match validator, mistake can be seen - no matching for closing parenthesis.

A little fix can be changing

$validator_arguments_pattern = "(\((?'arguments'.+,?)+\))?";

to

$validator_arguments_pattern = "(\((?'arguments'[^)]+,?)+\))?";

Still, however, closing parenthesis used as part of argument (ex. for regexp validator) will cause some problems...

@lezhnev74
Copy link
Owner

Thanks for reporting! Will get my hands on it soon.

@lezhnev74
Copy link
Owner

lezhnev74 commented Apr 15, 2018

Hey @Averor !
I spent a couple of hours thinking about this problem. I agree with your suggestion to improve regex with [^)]+. It definitely solves the problem of multiple sub-validators.

As you correctly mentioned in the end, another test failed because it uses parenthesis within the regular expression:
:string :regex(/so(me|ar)/,(((12)). The only "quick" fix I came up with was to add possibility to escape "closing parenthesis" like this: \). So the mentioned example became: :string :regex(/so(me|ar\)/,(((12\))

Now tests look green and probably I will merge this solution to master next week. However, the abovementioned solution is not "the best out there" and I hope to find a better one.

Let me know if you have other ideas of solving this issue.

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