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

@MartinSadovy MartinSadovy commented Jan 20, 2016

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

This comment has been minimized.

Copy link
Member

@dg dg commented Jan 20, 2016

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

@MartinSadovy

This comment has been minimized.

Copy link
Contributor Author

@MartinSadovy MartinSadovy commented Jan 20, 2016

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

PR #105

@dg

This comment has been minimized.

Copy link
Member

@dg dg commented Jan 20, 2016

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

@MartinSadovy

This comment has been minimized.

Copy link
Contributor Author

@MartinSadovy MartinSadovy commented Jan 20, 2016

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

@dg

This comment has been minimized.

Copy link
Member

@dg dg commented Jan 20, 2016

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

@dg

This comment has been minimized.

Copy link
Member

@dg dg commented Jan 20, 2016

@MartinSadovy

This comment has been minimized.

Copy link
Contributor Author

@MartinSadovy MartinSadovy commented Jan 21, 2016

@dg

This comment has been minimized.

Copy link
Member

@dg 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

This comment has been minimized.

Copy link
Contributor Author

@MartinSadovy MartinSadovy commented Jan 21, 2016

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

This comment has been minimized.

Copy link
Member

@dg dg commented Jan 21, 2016

👍

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

@MartinSadovy

This comment has been minimized.

Copy link
Contributor Author

@MartinSadovy MartinSadovy commented Jan 21, 2016

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 in #105 Jan 21, 2016
@dg

This comment has been minimized.

Copy link
Member

@dg dg commented Jan 21, 2016

Thanks!

dg added a commit that referenced this issue Jan 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.