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

Inconsistent Form::PATTERN #104

Closed
MartinSadovy opened this issue Jan 20, 2016 · 12 comments
Closed

Inconsistent Form::PATTERN #104

MartinSadovy opened this issue Jan 20, 2016 · 12 comments

Comments

@MartinSadovy
Copy link
Contributor

When I use back references in pattern rule (Form::PATTERN), it creates different behaviour on client side and server side in validation, because in Validator class, input pattern is bracked.

Example pattern: (.)\1{2,}
Different back reference:

  • Client side is \1
  • Server side is \2

Before I create PR, I would like to know, why pattern is bracked. There are two options: remove these bracket, or add to brackes (here, here).

use Nette\Forms\Form;

$form = new Form;
#$form->getElementPrototype()->novalidate = true;  // uncomment = validate by server side

$form->addText('name', 'Name:')
    ->addRule(
        Form::PATTERN, 
        'Please, write text with three same characters consecutively', 
        '(.)\1{2,}'
    );
$form->addSubmit('send', 'Register');
if ($form->isSuccess()) {
    echo '<h2>Form was submitted and successfully validated</h2>';

}
echo $form; // renders the form

reference bug reporting in czech forum: https://forum.nette.org/cs/25332-invert-regularniho-vyrazu#p168360

@dg
Copy link
Member

dg commented Jan 20, 2016

Probably you can change (...) to (?:...) as fix.

@MartinSadovy
Copy link
Contributor Author

I don't think so. There are missing brackets. Pattern is bracketed only in javascript validator.

PR #105

@dg
Copy link
Member

dg commented Jan 20, 2016

To use (?:....) is not possible?

@MartinSadovy
Copy link
Contributor Author

if you think (?:(.)\1{2,}), answer is no. It is still \2

@dg
Copy link
Member

dg commented Jan 20, 2016

In this case documentation is wrong http://php.net/manual/en/regexp.reference.subpatterns.php

@dg
Copy link
Member

dg commented Jan 20, 2016

@MartinSadovy
Copy link
Contributor Author

@dg https://3v4l.org/3BUJe

@dg
Copy link
Member

dg commented Jan 21, 2016

Sorry I don't understand what you mean.

Just here put return (bool) Strings::match($control->getValue(), "\x01^(?:$pattern)\\z\x01u"); and here put return typeof arg === 'string' ? (new RegExp('^(?:' + arg + ')$')).test(val) : null;.

before I create PR, I would like to know, why pattern is bracked.

Because /^abc|def$/ is a different from /^(abc|def)$/.

@MartinSadovy
Copy link
Contributor Author

Oh, I see. I had understood that I use ?: in pattern (eg. in ->addRule). I did not note (only one pair of breckets), my fault, sorry. O:-)

yeah, now it works correctly.

MartinSadovy added a commit to MartinSadovy/forms that referenced this issue Jan 21, 2016
@dg
Copy link
Member

dg commented Jan 21, 2016

👍

btw commit message should be changed, isn't it?

@MartinSadovy
Copy link
Contributor Author

Validator: pattern: supports back reference to Validator: fix different behaviour client and server side while use back reference, is not too long, or actual is ok?

@dg dg closed this as completed in #105 Jan 21, 2016
@dg
Copy link
Member

dg commented Jan 21, 2016

Thanks!

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