Review main Merged

88005[FEATURE] Introduce regex based replacements for slugs

André Buchmann CR +2 V +2 Normal +140 −1 updated 03/27/25, 17:13

Commit message

This change introduces new slug field `generatorOption`
configuration to define replacement regexp patterns,
which are executed on each slug field value before plain
replacement (case-sensitive) or normalization and allows
now to define case-insensitve or positional based replace
patterns while mitigating the need to use `postModifiers`
hook to reprocess all fields and records again.

Improves overall slug generation a little bit.

Review

  • Code review CR +2 Done
    • Benni Mack +2
    • Stefan Bürk +1
  • Verified V +2 Done
    • Benni Mack +2
    • Stefan Bürk +1
    • core-ci +1 CI

Issues 1

Files 3

Review log 2228

Show 23 earlier messages
  1. André Buchmann uploaded patch set 1 02/03/25, 21:41

  2. core-ci voted on patch set 1 V +1 02/03/25, 21:48 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/73447

  3. Mathias Brodala commented on patch set 1 02/03/25, 22:40

    SlugHelperTest.php:469

    Is this a literal replacement of "/cow/i" or a RegEx one? IMO ambiguity like this should be avoided. E.g. by requiring a string prefix, use a nested array syntax or introduce a new option next to "replacements".
  1. Garvin Hicking commented on patch set 1 02/04/25, 06:19

    How about using a new "regexpReplacements" key instead? That would also allow to use custom regexp delimiters (I often use '@' instead of '/'), and prevent the hardcoded quoting? (this would then classify as a feature instead of task, limiting it to main - but I think due to a possibly breakig change we should prefer that?)
  2. André Buchmann uploaded patch set 2 V +1 02/04/25, 09:53

  3. Mathias Brodala commented on patch set 2 02/04/25, 09:57

    SlugHelper.php:167

    This is obsolete now and must be removed.

    Feature-106072-IntroduceRegexBasedReplacementsForSlugs.rst:27

    Replace ... with "bar", ignoring casing

    Feature-106072-IntroduceRegexBasedReplacementsForSlugs.rst:28

    parentheses

    SlugHelperTest.php:469 Reply

    Done
  4. André Buchmann commented on patch set 1 02/04/25, 09:58

    Reply

    Thanks. Creating a dedicated "regexReplacements" definition as a feature sounds way better! I've pushed a new patchset therefore. Added a test with @ delimiter to make sure this works also. However I'm thinking if it's enough to add a regexReplacements option here or if we rather should implement an event to have it customizeable? Maybe could also deprecate the postModifiers hooks in favor of events?

    SlugHelperTest.php:469 Reply

    Thank you for the input. Yeah, the "/cow/i" case can be seen both ways... I'll create a new propose with a separate definition array for regex replacements.
  5. core-ci voted on patch set 2 V -1 02/04/25, 09:59 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/73477

  6. André Buchmann uploaded patch set 3 V -1 02/04/25, 09:59

  7. Mathias Brodala commented on patch set 3 02/04/25, 10:02

    SlugHelper.php:167 Reply

    Done
  8. core-ci voted on patch set 3 V -1 02/04/25, 10:06 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/73478

  9. André Buchmann uploaded patch set 4 V -1 02/04/25, 10:11

  10. André Buchmann commented on patch set 4 02/04/25, 10:12

    Feature-106072-IntroduceRegexBasedReplacementsForSlugs.rst:27 Reply

    Done

    Feature-106072-IntroduceRegexBasedReplacementsForSlugs.rst:28 Reply

    Done
  11. core-ci voted on patch set 4 V +1 02/04/25, 10:17 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/73479

  12. Garvin Hicking commented on patch set 4 02/04/25, 13:21

    Reply

    Cool, thanks for the initiative. I do think an extra key is creating "bloat". An event sounds nice but is way harder for integrators to apply, compared to the generatorOption. Personally I'd thus be in favor of this specific regexpreplacement...
  13. André Buchmann commented on patch set 4 02/05/25, 11:03

    Reply

    okay, let's go with the generatorOption :-)
  14. Stefan Bürk commented on patch set 4 CR -1 02/07/25, 12:26

    Need to have a look ....
  15. Stefan Bürk commented on patch set 4 03/27/25, 16:30

    SlugHelper.php:170

    This is not safe. In case invalid regexp pattern is provided, it does not return a string and leading to an type error afterwards. On top of this, warnings may be emitted depending on the settings (not suppressed): > preg_replace(): Delimiter must not be alphanumeric, backslash, or NUL
  16. Stefan Bürk commented on patch set 4 03/27/25, 16:35

    SlugHelper.php:170 Reply

    With multiple patterns, no pattern is replaced when one pattern is invalid with the current solution.
  17. Stefan Bürk commented on patch set 4 03/27/25, 16:37

    Reply

    On it ... testing & fixing ...
  18. Stefan Bürk uploaded patch set 5 CR -1 V +1 03/27/25, 16:56

  19. Stefan Bürk commented on patch set 5 03/27/25, 16:56

    Reply

    Done

    SlugHelper.php:170 Reply

    Done
  20. Stefan Bürk uploaded patch set 6 03/27/25, 16:57

  21. core-ci voted on patch set 5 V +1 03/27/25, 17:04 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/76486

  22. core-ci voted on patch set 6 V +1 03/27/25, 17:05 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/76487

  23. Stefan Bürk voted on patch set 6 CR +1 V +1 03/27/25, 17:06

  24. Benni Mack voted on patch set 6 CR +2 V +2 03/27/25, 17:12

  25. Benni Mack merged patch set 7 03/27/25, 17:13