Review main Abandoned

68762[FEATURE] Introduce regular expression validation in FormEngine

Johannes Schlier CR 0 V 0 Normal +64 −0 updated 07/04/23, 13:12

Commit message

A new JavaScript based regular expression validation rule
is added to FormEngine. This allows for flexible and custom
validations in specialised cases, e.g. standardized formats,
which previously required custom fields or dedicated evaluation
classes.

Therefore, TCA now features a new property `regularExpression`
with two options:

* `expression`: The regular expression, e.g. `^-?\d{1,2}(,|.)\d{4,7}$`
* `modifier`: Pattern modifiers, e.g. `i`

Review

  • Code review CR 0
  • Verified V 0

Issues 1

Files 3

Review log 1832

Show 37 earlier messages
  1. Johannes Schlier uploaded patch set 1 04/12/21, 11:11

  2. TYPO3com voted on patch set 1 V +1 04/12/21, 11:19 Completed build in 07m 22s on Mon, 12 Apr, 11:19 AM Test Summary: 33267 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-10615

  3. core-ci voted on patch set 1 V +1 04/12/21, 11:22 Core CI is happy: https://core.b13.com/typo3-core/typo3.cms/-/pipelines/2191

  4. Andreas Kienast commented on patch set 1 CR -1 04/12/21, 12:29

    Thank you for your contribution. I've downvoted this patch as-is for two reasons: 1.) a ReST file describing the feature and its impact is missing (https://forger.typo3.com/utilities/rst) 2.) Features must not get backported to non-master versions (in this case 10.4), unless there is a ultra important reasoning
  5. Johannes Schlier uploaded patch set 2 04/12/21, 13:41

  6. TYPO3com voted on patch set 2 V +1 04/12/21, 13:50 Completed build in 08m 17s on Mon, 12 Apr, 01:50 PM Test Summary: 33267 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-10616

  7. core-ci voted on patch set 2 V +1 04/12/21, 13:52 Core CI is happy: https://core.b13.com/typo3-core/typo3.cms/-/pipelines/2193

  1. Johannes Schlier commented on patch set 2 04/13/21, 14:23

    Reply

    Thanks for the review. I added a ReST file. I could not build the documentation locally, but hope that it's fine as it is. The backport has no real important reason. I simply thought it's not a complicated patch and could therefore easily be backported. Would be nice for some projects of ours with TYPO3 10 - but I can simply include a local patch until those are updated to TYPO3 11. Feel free to suggest more changes.
  2. Oli Bartsch uploaded patch set 3 04/13/21, 15:23

  3. Oli Bartsch uploaded patch set 4 04/13/21, 15:26

  4. TYPO3com voted on patch set 3 V +1 04/13/21, 15:30 Completed build in 07m 41s on Tue, 13 Apr, 03:30 PM Test Summary: 33267 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-10649

  5. TYPO3com voted on patch set 4 V +1 04/13/21, 15:34 Completed build in 07m 31s on Tue, 13 Apr, 03:34 PM Test Summary: 33267 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-10650

  6. core-ci voted on patch set 3 V +1 04/13/21, 15:35 Core CI is happy: https://core.b13.com/typo3-core/typo3.cms/-/pipelines/2231

  7. core-ci voted on patch set 4 V +1 04/13/21, 15:40 Core CI is happy: https://core.b13.com/typo3-core/typo3.cms/-/pipelines/2232

  8. Oli Bartsch uploaded patch set 5 04/13/21, 16:15

  9. Oli Bartsch uploaded patch set 6 04/13/21, 16:16

  10. Oli Bartsch voted on patch set 6 V +1 CR +1 04/13/21, 16:17

  11. TYPO3com voted on patch set 5 V +1 04/13/21, 16:23 Completed build in 07m 53s on Tue, 13 Apr, 04:23 PM Test Summary: 33267 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-10651

  12. TYPO3com voted on patch set 6 V +1 04/13/21, 16:24 Completed build in 07m 35s on Tue, 13 Apr, 04:24 PM Test Summary: 33267 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-10652

  13. core-ci voted on patch set 5 V +1 04/13/21, 16:27 Core CI is happy: https://core.b13.com/typo3-core/typo3.cms/-/pipelines/2233

  14. core-ci voted on patch set 6 V +1 04/13/21, 16:31 Core CI is happy: https://core.b13.com/typo3-core/typo3.cms/-/pipelines/2234

  15. Oliver Hader commented on patch set 6 CR -1 04/19/21, 09:35

    It looks like this is client-side validation only - are there plans to extend that to server-side validation in DataHandler as well. I'm giving a -1 since I fear that validation introduced with this change is used with the expectation it also concerns persistence. The missing server-side part might lead to new security-related aspects...
  16. Oliver Hader commented on patch set 6 04/19/21, 09:45

    Feature-23633-RegularExpressionValidationInFormEngine.rst:33 Unresolved

    In the long run, I could imagine something like ``` latitute type: input validation: regularExpression: pattern: ^\d+$ modifier: null preset: int transformation: search: , replace: . ``` Let's skip the `transformation` part for the time being (→ later™). The `preset` part in `validation` might later be used like the current presets we have with `eval` - thus, having a way to combine and normalize `eval` with new `regularExpression`.
  17. Johannes Schlier commented on patch set 6 05/04/21, 14:15

    Reply

    True, this is client-side validation only. Since the backend heavily relies on JavaScript anyways I figured this would be enough for all cases, but I can see that some might expect it to do something server-side. I don't quite know where to add this, besides in the DataHandler method "checkValueForInput". Everything is given there, but all I can manage is to change or remove the value passed to the database: ``` if (isset($tcaFieldConf['regularExpression']) && isset($tcaFieldConf['regularExpression']['expression'])) { $matches = []; $expression = '/' . $tcaFieldConf['regularExpression']['expression'] . '/' . $tcaFieldConf['regularExpression']['modifier'] ?? ''; try { $result = preg_match( $expression, $value, $matches ); if ($result === 0 || $result === false) { $res['value'] = ''; } } catch(Exception $e) { $res['value'] = ''; } } ``` I would prefer to actually send the user back with a FlashMessage. Otherwise the editor simply returns to the edit form with an empty field, probably without noticing that change. It seems the DataHandler is not built for this type of validation. If the given "$value" variable is overriden or set to an empty string instead of the "$res['value']" a database error is produced in the backend. This way at least the user is pointed to the correct field. Maybe within the EditDocumentController? It does not contain any similar cases yet. If anyone has any ideas or pointers where to add this, I'd glady add server side validation. It seems that to properly and cleanly add real validation (and not simply manipulation into certain ranges or something similar) some pretty big structural changes would have to be introduced.
  18. Oli Bartsch voted on patch set 6 V 0 CR 0 05/04/21, 14:24

  19. Benni Mack wrote 11/29/21, 10:06

    Change destination moved from master to main
  20. Benni Mack updated the commit message in patch set 7 11/29/21, 13:21

  21. core-ci voted on patch set 7 V +1 11/29/21, 13:44 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/20006

  22. Simon Schaufelberger uploaded patch set 8 04/26/22, 19:57

  23. core-ci voted on patch set 8 V -1 04/26/22, 20:24 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26475

  24. Andreas Kienast wrote 09/22/22, 11:08

    Removed reviewer Andreas Kienast.
  25. Benni Mack abandoned the change 07/04/23, 13:12

    I will abandon this change now, as we need to rework this completely anyways. Can be restored later-on