Invalid RegEx in DefinitionValidator
PHP Version
8.2.13
Shopware Version
6.5.8.4
Expected behaviour
I've created a plugin whose name ends with "s". In there are several custom entities and their respective definitions.
Usually I run bin/console dal:validate and was quite surprised to see not a single issue with my blindly created definitions and their entities.
I then intentionally created some issues inside of those definitions (Missing fields in the entity, missing reverse-associations, etc.) and was expecting the validation to find ANY issue at all.
Actual behaviour
Having spent some time on debugging, I eventually figured that my definitions were fully skipped due to a wrong RegEx.
How to reproduce
- Create a plugin whose namespace ends with an "s", e.g. "MyExamplePlugins"
- Create custom entities and definitions and make sure to add some mistakes in there
- Run the
dal:validatecommand and see it not noticing a single issue.
Explanation:
Here is the validator and its respective RegEx: DefinitionValidator
The |s part in the RegEx matches and considers your definition to be in a "Test" namespace when your plugin ends with "s" (Or any other part of the namespace).
Here's an example Regex101 link to see the issue.
I would have created a PullRequest and tried fixing it myself if I knew why the |s was added in the first place, but I couldn't figure that out - sorry guys! 🥲
Drop me a hint what the intention was and I'll try to come up with a PR.
Lots of love 💙
We found the following existing issues which may help or are related to your topic:
- Entity definitions containing the word "Test" incorrectly excluded from validation
- [github] Entity definitions containing the word "Test" incorrectly excluded from validation
- Incorrect contact-form receiver validation-regex
- HappyPathValidator - Is that really the best solution? Ignores various options like e.g. groups in constraints and overrides original validator.
- NEXT-16508 - Fixed entity exists and not validators work correctly with composite constraints.
- If you mix up Definition and Entity the error can be improved
- HappyPathValidator - Is that really the best solution? Ignores various options like e.g. groups and overrides original validator. At least do not override the original validator
- Plugin configuration constraint violation error when reverting to inherit values
- NEXT-31615 - fix language mapping in SalesChannelValidator
- [Github] NEXT-19596 - fix language mapping in SalesChannelValidator
Thanks for bringing this up @PaddyS, and nice to see you here 💙
I guess the intention of this regex is to check for namespaces containing "Test" or "Tests" to be excluded from the validation. The pipe |s makes it go "Test" OR "s" instead.
It should look something like Tests? instead (last token before ? is optional).