-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Fix ModelInstance RegEx pattern for class names. #11650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix ModelInstance RegEx pattern for class names. #11650
Conversation
Changes '[A-Za-z_\\]+' for '[A-Za-z0-9_\\]+' to support namespaces with numbers.
To be processed together with #11062 as we agreed. |
@orlangur @MartinPeverelli This PR and #11062 propose using Starting numbers weren't allowed before, and I think opening xsd that way would result in a regression. Also, current expression allows expressions starting with underscores like I'd propose one of the following expressions:
What do you think? |
@adrian-martinez-interactiv4 I do agree with you that regexp from PR is too wide and allows invalid strings. As Model name potentially could be any valid PHP class name (FQCN to be precise) and according to PHP documentation full regexp should looks like:
|
@vkublytskyi http://php.net/manual/en/language.variables.basics.php has nothing to do with class names, it's about variables, http://php.net/manual/en/language.oop5.basic.php fits better. Looks like you added backslash by your own while referring to unrelated documentation page :D Leading digit is still allowed: https://regex101.com/r/U0VCMk/1 (don't forget about ^...$). Note that leading backslash MUST NOT be allowed. No reason to allow class names violating PSR-2 => probably leading lowercase letter is not needed to be allowed? Another place with FQCN regexp: https://github.com/magento/magento2/pull/11765/files It is not so bad as leading backslash or digit is not allowed, characters allowed are not so wide as in mentioned regexp though.
Let's pick the best variant in Slack and fix all places. |
@orlangur RegExp from PHP site describes any names in PHP ("the same rules as other labels in PHP") which could be: variables, class names, function names, method names, property names, constants. I've added backslash to apply this pattern to FQCN as FQCN is a sequence of names joined by a backslash. Also, not allowing leading backslash in Magento xml files (e.g. layouts, di, etc.) is ok. But blocks import process if someone specifies a valid model name with leading backslash is too hard and not necessary limitation. Of course, any regexp that we choose should be wrapped with |
@orlangur any updates? |
Closed due to inactivity. Feel free to re-open it if you wish to continue working on it. |
The updated XSD files forbid the usage of digits in the class or namespaces for the modelInstance value.
Description
Changes
'[A-Za-z_\\]+'
for'[A-Za-z0-9_\\]+'
to support namespaces with digits.Fixed Issues (if relevant)
Manual testing scenarios
Create a module with a vendor name containing a digit. The following XML should be valid.
Contribution checklist