It appears that Patterns in Form validation are not functioning as expected. For example when using the Pattern Validator: ##-###-##@@ and attempting to submit a form with the value: 12-123-12UP for a field that has that validator. Validation fails when it should succeed.

Running 7.x-1.15 with PHP 7.3.1.

Comments

aroseman18 created an issue. See original summary.

liam morland’s picture

I just tried it on a test site and it works as expected for me, at least under PHP 5.6. I don't think the PHP version would matter. Please verify that there is not additional whitespace in either the pattern or the test data.

aroseman18’s picture

There is no whitespace in the pattern or data.
The only thing that changed on the site was PHP version so that was my first guess.

liam morland’s picture

Please try changing your PHP version to see if that is actually the problem. You could try to reproduce just the validation snippet on another server; see webform_validation.validators.inc.

liam morland’s picture

Is this still a problem?

liam morland’s picture

Version: 7.x-1.15 » 7.x-1.x-dev
Status: Active » Closed (cannot reproduce)

If this is still a problem please re-open and provide details.

swigle’s picture

I've got the same issue. Trying to validate a postalcode useing "#### @@" validator.
This always fails.

It's a site of a client and they just started noticing this. We went from php 7.0X to 7.3X last week, but i can't easily change it back to test.

liam morland’s picture

I can't reproduce this problem in my test environment on either PHP 5.6 or PHP 7.2. I suggest downgrading PHP to see if that is the problem. Or add debugging code to see why it is failing.

swigle’s picture

Since i had some spare time, i fired up an old cluster with PHP 7.0.x to test with.
I created a webform with a single textfield, added a pattern validation of "#### @@" and tried to enter data.

On PHP 7.0.x this works as intended; 1234AB doesn't get validated, 1234 AB is valid.

Switching back to our new cluster with PHP 7.3.4, the exact same page doesn't validate 1234AB as well as 1234 AB so the php version would seem the culprit.
Sadly no errors in the logs or in drupal. It would seem the methods used to check the input versus the pattern have changed in this PHP version which results in the validator always returning invalid.

liam morland’s picture

Status: Closed (cannot reproduce) » Active

It will take adding some debugging code to see what the difference is.

swigle’s picture

Any news on this? All pattern validators aren't working for us, which is kinda a pain :)

liam morland’s picture

You could switch to using regex or add some debugging code to try to figure out what is happening.

liam morland’s picture

Using the latest development version of webform_validation, please create a minimal test case.

jay.dansand’s picture

Status: Active » Needs review
StatusFileSize
new865 bytes

I just stumbled into this today after we upgraded to PHP 7.3 yesterday. The problem is that preg_quote() changed behavior in 7.3 and now escapes # to \#. When webform_validation_webform_validation_validate() creates $pattern to test the input, # becomes \# becomes \[0-9] (instead of [0-9]) and that regex will never match numbers. Attached is a minimal patch that tests the PHP version and de-escapes "#" in the test pattern.

liam morland’s picture

Status: Needs review » Needs work

Thanks for the patch. Instead of duplicating the call to str_replace(), have the line with version_compare() return either '#' or '\#' and use that in the str_replace() call.

jay.dansand’s picture

Priority: Normal » Major
Status: Needs work » Needs review
StatusFileSize
new856 bytes

Sure.

Based on priority levels for issues, this should be major. All pattern-based validators using # are broken for PHP 7.3+ with no warning to admin and obvious disruption for site visitors. Let's just get the fix in. :)

Happy holidays!

liam morland’s picture

Status: Needs review » Fixed

Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.