-
-
Notifications
You must be signed in to change notification settings - Fork 452
Replace Zend_Validate with symfony/validator
#4612
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
aec1a31
6111f8c
e3fa261
4fed24d
89bcb2b
ed884ad
54f5892
c323535
9cb98e5
69903cf
65cd4ae
d7c6049
0f6e197
b6c03ae
3583b5f
4fe1c54
0411938
6f91392
37dd0ef
3e7be18
00f3c49
9b6948a
f00f13b
fd8f1bb
0c59f9d
793e310
cd473a5
478a2ad
e3207a6
b1606bc
2869035
7df9000
dcbfdcf
616d488
1de9167
d6752f0
3df9d26
82c5d79
70c3f7d
7786276
aad34d6
d54e5de
b13ea95
dc6a5cd
47a37ad
df9ce5f
ec9aa27
b91ffdd
f718560
d521531
f6d55e2
198a279
cc86b05
39e5606
16fe79d
7932e12
ff3323f
bdafcbd
7e4a3a6
95f2c05
9b94d22
38bc13a
42b7f7a
11174fa
2bc9d0a
321267a
06dcb87
83ec8c3
1531b5c
8c842dd
dacac2d
dc8473d
860b20b
cf27ee9
f63bdbd
4a50620
3223cc5
ef0fe03
233ab75
86b7223
1a6d9b8
765fdaf
f03dc87
3e4d6d6
5e1cccd
1c3fdaf
b3e44eb
762b6b0
80782fe
ad90358
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,8 @@ | |
| * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) | ||
| */ | ||
|
|
||
| use Respect\Validation\Validator as v; | ||
|
|
||
| /** | ||
| * API2 catalog_product Validator | ||
| * | ||
|
|
@@ -122,18 +124,19 @@ public function isValidData(array $data) | |
| * | ||
| * @param array $data | ||
| * @param Mage_Eav_Model_Entity_Type $productEntity | ||
| * @throws Mage_Api2_Exception | ||
| */ | ||
| protected function _validateAttributes($data, $productEntity) | ||
| { | ||
| if (!isset($data['attribute_set_id']) || empty($data['attribute_set_id'])) { | ||
| if (empty($data['attribute_set_id'])) { | ||
| $this->_critical('Missing "attribute_set_id" in request.', Mage_Api2_Model_Server::HTTP_BAD_REQUEST); | ||
| } | ||
| if (!isset($data['type_id']) || empty($data['type_id'])) { | ||
| if (empty($data['type_id'])) { | ||
|
||
| $this->_critical('Missing "type_id" in request.', Mage_Api2_Model_Server::HTTP_BAD_REQUEST); | ||
| } | ||
| // Validate weight | ||
| if (isset($data['weight']) && !empty($data['weight']) && $data['weight'] > 0 | ||
| && !Zend_Validate::is($data['weight'], 'Between', [0, self::MAX_DECIMAL_VALUE]) | ||
| if (!empty($data['weight']) && $data['weight'] > 0 | ||
| && !v::floatVal()->between(0, self::MAX_DECIMAL_VALUE)->validate($data['weight']) | ||
| ) { | ||
| $this->_addError('The "weight" value is not within the specified range.'); | ||
| } | ||
|
|
@@ -278,8 +281,11 @@ protected function _validateSku($data) | |
| if ($this->_isUpdate() && !isset($data['sku'])) { | ||
| return true; | ||
| } | ||
| if (!Zend_Validate::is((string) $data['sku'], 'StringLength', ['min' => 0, 'max' => 64])) { | ||
| $this->_addError('SKU length should be 64 characters maximum.'); | ||
|
|
||
| $skuMaxLength = Mage_Eav_Model_Entity_Attribute::ATTRIBUTE_CODE_MAX_LENGTH; | ||
|
|
||
| if (!v::stringType()->length(0, $skuMaxLength)->validate((string) $data['sku'])) { | ||
| $this->_addError(sprintf('SKU length should be %d characters maximum.', $skuMaxLength)); | ||
| } | ||
| } | ||
|
|
||
|
|
||
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.
Changed from
!isset($data['attribute_set_id']) || empty($data['attribute_set_id'])to justempty($data['attribute_set_id']). While functionally equivalent (empty() checks both isset and truthiness), this changes the behavior subtly:empty()will return true for'0'and0, whereas the original would only check if the key exists and has a truthy value. Verify this doesn't break validation for legitimate zero values.