-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
[EAV] Improving the EAV attribute code validation, by not allowing to use n… #20526
[EAV] Improving the EAV attribute code validation, by not allowing to use n… #20526
Conversation
Hi @eduard13. Thank you for your contribution
For more details, please, review the Magento Contributor Assistant documentation |
@@ -0,0 +1,63 @@ | |||
<?php | |||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a good idea to use strict types within a scope of new implementations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, the strict typing was declared.
Also do you think it's a good idea to rename this variable name into a less meaningful name (in order to fix the failing pipeline)?
Code $attributeCodeValidator = null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have implemented the naming in the same manner as other validators. So, it's ok.
You could use an alias in the use
section for this class. Something like:
use Magento\Eav\Model\Validator\Attribute\Code as AttributeCodeValidator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rogyar the alias was added.
@eduard13 |
@irajneeshgupta, I don't think that we should add a such validation, as you're able to create attributes with capitalized letters from the admin panel, moreover I don't see what issue can occur by having such attributes. |
I think validation pattern should be same for both admin and creation of attributes programmatically...if admin user can create such attributes , then why such limitations for developers hence i requested you to add it. Thank you. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @eduard13 thanks for the pull request! Please see my code review notes
$validatorAttrCode = new \Zend_Validate_Regex( | ||
['pattern' => '/^[a-zA-Z\x{600}-\x{6FF}][a-zA-Z\x{600}-\x{6FF}_0-9]{0,30}$/u'] | ||
['pattern' => '/^[a-zA-Z]+[a-zA-Z0-9_]*$/u'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to move this pattern to a constant, as it is used more than once (I think added validation class is a good place for such constant to be declared).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense.
Thanks.
* @return bool | ||
* @throws LocalizedException | ||
*/ | ||
public function isValid($attributeCode): bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method named isValid
should return bool and should not throw an exception. Validation messages should be collected using _addMessages
parent method. Appropriate exceptions should be thrown if needed by client classes (that can access messages via getMessages
validator method)
* | ||
* Validation EAV attribute code | ||
*/ | ||
class Code extends AbstractValidator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class Code extends AbstractValidator | |
class Code extends AbstractValidator |
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Eav\Model\Validator\Attribute; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please cover the validator class with a unit test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The class was covered by Unit Test, and also all the related tests (unit, integration) were updated.
… Covering the new validator class by Unit Test
@sivaschenko thank you for the review, I've updated the implementation. Could you please review the updates? |
I believe this pull request also resolves #20766 |
Hi @rogyar, thank you for the review. |
✔️ QA passed |
Hi @eduard13, thank you for your contribution! |
…t allowing to use n… #20526
@magento-engcom-team is there any reason of marking the PR just as an Improvement? Not even a |
Hi @eduard13 , right now only members of the Community Engineering team are able to set up achievements for pull requests, that why our automated tool removed them. I reverted the changes because your pull request really complex and should be rewarded. |
Hi @sidolov, glad to hear that, but whom should I ping for recalculating the reward points for March? |
Hi @eduard13 , points already recalculated |
Description (*)
This PR improves the attribute code validation, namely while creating the attribute programmatically. Before you were able to create (programmatically) an attribute with not allowed chars.
Fixed Issues (if relevant)
Manual testing scenarios (*)
Contribution checklist (*)