Project

General

Profile

Actions

Bug #91340

closed

RegEx validator in EXT:form does not support negative lookbehind

Added by Peter Kraume almost 4 years ago. Updated almost 2 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Form Framework
Start date:
2020-05-07
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
12
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:
Remote Sprint

Description

I tried to use this regular expression to allow all email addresses but not those ending with @qq.com:

/^.+@.+(?<!@qq.com)$/g

There are two problem with the regex validator of EXT:form when you want to use an expression with negative lookbehind:

1. The GUI of the TYPO3 backend cuts the regular expression when there is a < in the expression.
2. Even if you edit the yaml file in the file system and enter the expression manually, you end up with the following exception:

TYPO3\\CMS\\Extbase\\Validation\\Exception\\InvalidValidationOptionsException: regularExpression \"/^.+@.+(?<!@qq.com)$/g\" in RegularExpressionValidator contained an error. in /var/www/html/public/typo3/sysext/extbase/Classes/Validation/Validator/RegularExpressionValidator.php:51

Related issues 2 (0 open2 closed)

Related to TYPO3 Core - Bug #90640: ext:form - RegularExpressionValidator with empty value will lead to exceptionClosedBjörn Jacob2020-03-04

Actions
Related to TYPO3 Core - Bug #102143: Regular Expression is cut offClosed2023-10-11

Actions
Actions #1

Updated by Björn Jacob over 2 years ago

Right now, we tend to not implement the first part. Since "<" is part of an HTML tag, allowing it could create security issues. The second part of the issue description seems valid :)

Actions #2

Updated by Björn Jacob about 2 years ago

  • Related to Task #70889: In a ModuleController use iconFactory from moduleTemplate added
Actions #3

Updated by Björn Jacob about 2 years ago

  • Related to deleted (Task #70889: In a ModuleController use iconFactory from moduleTemplate)
Actions #4

Updated by Björn Jacob about 2 years ago

  • Related to Bug #90640: ext:form - RegularExpressionValidator with empty value will lead to exception added
Actions #5

Updated by Björn Jacob about 2 years ago

  • Sprint Focus set to Remote Sprint

We can work on the second part. The GUI does not support the regex validator anymore (soon), see #90640.

Actions #6

Updated by Björn Jacob almost 2 years ago

  • TYPO3 Version changed from 10 to 12

The behaviour is still the same on current main.

Actions #7

Updated by Elias Häußler almost 2 years ago

Hi Peter,

I just tested this on latest main with the following form definition:

renderingOptions:
  submitButtonLabel: Submit
type: Form
identifier: test91340
label: 'test 91340'
prototypeName: standard
renderables:
  -
    renderingOptions:
      previousButtonLabel: 'Previous step'
      nextButtonLabel: 'Next step'
    type: Page
    identifier: page-1
    label: Step
    renderables:
      -
        defaultValue: ''
        validators:
          -
            identifier: EmailAddress
          -
            identifier: RegularExpression
            options:
              regularExpression: '/^.+@.+(?<!@qq.com)$/g'
        type: Email
        identifier: email-1
        label: 'Email address'

With this configuration, on form submit I get the following exception:

#1476107295 TYPO3\CMS\Core\Error\Exception
PHP Warning: preg_match(): Unknown modifier 'g' in /var/www/html/typo3/sysext/extbase/Classes/Validation/Validator/RegularExpressionValidator.php line 42

This is correct, since the regex should be

-regularExpression: '/^.+@.+(?<!@qq.com)$/g'
+regularExpression: '/^.+@.+(?<!@qq\.com)$/'

When using the modified regex, I get

You must enter a valid value. Please refer to the description of this field.

when entering foo@qq.com as e-mail address, which is expected behavior.

Additionally, I can successfully submit the form when using a different e-mail address, e.g. foo@bar.com.

That's why I'd say this issue is already resolved. Can you confirm?

Actions #8

Updated by Björn Jacob almost 2 years ago

  • Status changed from New to Needs Feedback
Actions #9

Updated by Peter Kraume almost 2 years ago

Hi guys,

thx a lot for taking care of my issue. I've tested the regular expression as suggested by Elias and that worked fine with TYPO3 11.5.12.
So I would say that this issue can be closed. Thx again!

Actions #10

Updated by Björn Jacob almost 2 years ago

  • Status changed from Needs Feedback to Closed

Thanks Peter for your feedback. Perfect.

Actions #11

Updated by Elias Häußler 6 months ago

  • Related to Bug #102143: Regular Expression is cut off added
Actions

Also available in: Atom PDF