shopware icon indicating copy to clipboard operation
shopware copied to clipboard

Invalid RegEx in DefinitionValidator

Open PaddyS opened this issue 2 years ago • 2 comments

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:validate command 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 💙

PaddyS avatar Feb 12 '24 14:02 PaddyS

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). image

bschulzebaek avatar Feb 12 '24 15:02 bschulzebaek