Skip to content
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
aec1a31
added respect/validation
sreichel Feb 5, 2025
6111f8c
replaced Zend_Validate::
sreichel Feb 5, 2025
e3fa261
replaced Zend_Validate_File_Extension
sreichel Feb 6, 2025
4fed24d
doc
sreichel Feb 6, 2025
89bcb2b
phpstan
sreichel Feb 7, 2025
ed884ad
test symfony
sreichel Feb 8, 2025
54f5892
Merge branch 'main' into validation
sreichel Mar 29, 2025
c323535
use symfony (not tested)
sreichel Mar 30, 2025
9cb98e5
phpstan baseline
sreichel Mar 30, 2025
69903cf
Merge branch 'main' into validation
sreichel Apr 6, 2025
65cd4ae
some fixes
sreichel Apr 6, 2025
d7c6049
some updates
sreichel Apr 6, 2025
0f6e197
added test
sreichel Apr 6, 2025
b6c03ae
added test
sreichel Apr 6, 2025
3583b5f
Merge remote-tracking branch 'origin/validation' into validation
sreichel Apr 7, 2025
4fe1c54
fix file cannot be empty
sreichel Apr 9, 2025
0411938
renaming
sreichel Apr 9, 2025
6f91392
Merge branch 'main' into validation
sreichel Apr 9, 2025
37dd0ef
update
sreichel Apr 9, 2025
3e7be18
update
sreichel Apr 9, 2025
00f3c49
test
sreichel Apr 9, 2025
9b6948a
updated test
sreichel Apr 10, 2025
f00f13b
updated test
sreichel Apr 10, 2025
fd8f1bb
updated test
sreichel Apr 10, 2025
0c59f9d
updated test
sreichel Apr 10, 2025
793e310
update
sreichel Apr 10, 2025
cd473a5
updated test
sreichel Apr 10, 2025
478a2ad
typo
sreichel Apr 10, 2025
e3207a6
added test
sreichel Apr 11, 2025
b1606bc
update
sreichel Apr 12, 2025
2869035
fix + test
sreichel Apr 14, 2025
7df9000
update
sreichel Apr 14, 2025
dcbfdcf
skip valid data, to not send email
sreichel Apr 14, 2025
616d488
update
sreichel Apr 14, 2025
1de9167
updated tests
sreichel Apr 14, 2025
d6752f0
rector
sreichel Apr 14, 2025
3df9d26
rector
sreichel Apr 14, 2025
82c5d79
updated tests
sreichel Apr 14, 2025
70c3f7d
updated tests -. fix
sreichel Apr 14, 2025
7786276
updated tests
sreichel Apr 14, 2025
aad34d6
split unit tests
sreichel Apr 14, 2025
d54e5de
test
sreichel Apr 14, 2025
b13ea95
fix later
sreichel Apr 14, 2025
dc6a5cd
updated tests
sreichel Apr 14, 2025
47a37ad
typo
sreichel Apr 14, 2025
df9ce5f
updated tests
sreichel Apr 15, 2025
ec9aa27
baseline phpunit
sreichel Apr 15, 2025
b91ffdd
Merge branch 'main' into validation
sreichel Apr 15, 2025
f718560
merge tests from main
sreichel May 7, 2025
d521531
Merge branch 'main' into validation
sreichel May 7, 2025
f6d55e2
Merge branch 'main' into validation
sreichel May 7, 2025
198a279
simplified for now
sreichel May 7, 2025
cc86b05
phpstan
sreichel May 7, 2025
39e5606
Merge branch 'main' into validation
sreichel Jun 15, 2025
16fe79d
Merge branch 'main' into validation
sreichel Jul 21, 2025
7932e12
composer update
sreichel Jul 21, 2025
ff3323f
updated tests
sreichel Jul 21, 2025
bdafcbd
updated tests
sreichel Jul 21, 2025
7e4a3a6
Merge branch 'main' into validation
sreichel Oct 20, 2025
95f2c05
refactor
sreichel Oct 23, 2025
9b94d22
Merge branch 'main' into validation
sreichel Oct 24, 2025
38bc13a
refactor
sreichel Oct 25, 2025
42b7f7a
fixed installer
sreichel Oct 26, 2025
11174fa
phpcsfixer
sreichel Oct 26, 2025
2bc9d0a
phpmd
sreichel Oct 26, 2025
321267a
phpstorm meta
sreichel Oct 26, 2025
06dcb87
phpstan
sreichel Oct 26, 2025
83ec8c3
tests
sreichel Oct 26, 2025
1531b5c
phpstan
sreichel Oct 26, 2025
8c842dd
refactor
sreichel Oct 26, 2025
dacac2d
typo
sreichel Oct 26, 2025
dc8473d
remove file
sreichel Oct 26, 2025
860b20b
typo
sreichel Oct 26, 2025
cf27ee9
cleanup
sreichel Oct 26, 2025
f63bdbd
cleanup
sreichel Oct 26, 2025
4a50620
typo
sreichel Oct 26, 2025
3223cc5
naming
sreichel Oct 26, 2025
ef0fe03
cleanup
sreichel Oct 26, 2025
233ab75
test
sreichel Oct 26, 2025
86b7223
phpstan
sreichel Oct 26, 2025
1a6d9b8
Merge branch 'main' into validation
sreichel Oct 26, 2025
765fdaf
tests
sreichel Oct 26, 2025
f03dc87
Update app/code/core/Mage/Core/Helper/Validate.php
sreichel Oct 26, 2025
3e4d6d6
Update app/code/core/Mage/Admin/Model/User.php
sreichel Oct 26, 2025
5e1cccd
Update app/code/core/Mage/Newsletter/Model/Template.php
sreichel Oct 26, 2025
1c3fdaf
Merge branch 'main' into validation
sreichel Oct 27, 2025
b3e44eb
Merge branch 'main' into validation
sreichel Oct 27, 2025
762b6b0
Merge branch 'main' into validation
sreichel Oct 27, 2025
80782fe
Merge branch 'main' into validation
sreichel Oct 27, 2025
ad90358
updated tests
sreichel Nov 1, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions app/code/core/Mage/Admin/Model/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
* Class Mage_Admin_Model_Block
*
Expand All @@ -40,20 +42,19 @@ protected function _construct()
/**
* @return array|true
* @throws Exception
* @throws Zend_Validate_Exception
*/
public function validate()
{
$errors = [];

if (!Zend_Validate::is($this->getBlockName(), 'NotEmpty')) {
if (!v::stringType()->notEmpty()->validate($this->getBlockName())) {
$errors[] = Mage::helper('adminhtml')->__('Block Name is required field.');
}
$disallowedBlockNames = Mage::helper('admin/block')->getDisallowedBlockNames();
if (in_array($this->getBlockName(), $disallowedBlockNames)) {
$errors[] = Mage::helper('adminhtml')->__('Block Name is disallowed.');
}
if (!Zend_Validate::is($this->getBlockName(), 'Regex', ['/^[-_a-zA-Z0-9]+\/[-_a-zA-Z0-9\/]+$/'])) {
if (!v::regex('/^[-_a-zA-Z0-9]+\/[-_a-zA-Z0-9\/]+$/')->validate($this->getBlockName())) {
$errors[] = Mage::helper('adminhtml')->__('Block Name is incorrect.');
}

Expand Down
15 changes: 8 additions & 7 deletions app/code/core/Mage/Admin/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
* Admin user model
*
Expand Down Expand Up @@ -579,25 +581,24 @@ public function getStartupPageUrl()
* Returns TRUE or array of errors.
*
* @return array|true
* @throws Zend_Validate_Exception
*/
public function validate()
{
$errors = new ArrayObject();

if (!Zend_Validate::is($this->getUsername(), 'NotEmpty')) {
if (!v::stringType()->notEmpty()->validate($this->getUsername())) {
$errors->append(Mage::helper('adminhtml')->__('User Name is required field.'));
}

if (!Zend_Validate::is($this->getFirstname(), 'NotEmpty')) {
if (!v::stringType()->notEmpty()->validate($this->getFirstname())) {
$errors->append(Mage::helper('adminhtml')->__('First Name is required field.'));
}

if (!Zend_Validate::is($this->getLastname(), 'NotEmpty')) {
if (!v::stringType()->notEmpty()->validate($this->getLastname())) {
$errors->append(Mage::helper('adminhtml')->__('Last Name is required field.'));
}

if (!Zend_Validate::is($this->getEmail(), 'EmailAddress')) {
if (!v::email()->validate($this->getEmail())) {
$errors->append(Mage::helper('adminhtml')->__('Please enter a valid email.'));
}

Expand Down Expand Up @@ -645,13 +646,13 @@ public function validate()
*
* @param string $password
* @return array|true
* @throws Zend_Validate_Exception
* @throws Exception
*/
public function validateCurrentPassword($password)
{
$result = [];

if (!Zend_Validate::is($password, 'NotEmpty')) {
if (!v::stringType()->notEmpty()->validate($password)) {
$result[] = $this->_getHelper('adminhtml')->__('Current password field cannot be empty.');
} elseif (is_null($this->getId()) || !Mage::helper('core')->validateHash($password, $this->getPassword())) {
$result[] = $this->_getHelper('adminhtml')->__('Invalid current password.');
Expand Down
9 changes: 5 additions & 4 deletions app/code/core/Mage/Admin/Model/Variable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
* Class Mage_Admin_Model_Variable
*
Expand All @@ -38,18 +40,17 @@ protected function _construct()
}

/**
* @return array|bool
* @return array|true
* @throws Exception
* @throws Zend_Validate_Exception
*/
public function validate()
{
$errors = [];

if (!Zend_Validate::is($this->getVariableName(), 'NotEmpty')) {
if (!v::stringType()->notEmpty()->validate($this->getVariableName())) {
$errors[] = Mage::helper('adminhtml')->__('Variable Name is required field.');
}
if (!Zend_Validate::is($this->getVariableName(), 'Regex', ['/^[-_a-zA-Z0-9\/]*$/'])) {
if (!v::regex('/^[-_a-zA-Z0-9\/]*$/')->validate($this->getVariableName())) {
$errors[] = Mage::helper('adminhtml')->__('Variable Name is incorrect.');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
* System config email field backend model
*
Expand All @@ -22,11 +24,14 @@
*/
class Mage_Adminhtml_Model_System_Config_Backend_Email_Address extends Mage_Core_Model_Config_Data
{
/**
* @throws Mage_Core_Exception
*/
protected function _beforeSave()
{
$value = $this->getValue();
if (!Zend_Validate::is($value, 'EmailAddress')) {
Mage::throwException(Mage::helper('adminhtml')->__('Invalid email address "%s".', $value));
$email = $this->getValue();
if (!v::email()->validate($email)) {
Mage::throwException(Mage::helper('adminhtml')->__('Invalid email address "%s".', $email));
}
return $this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
* Catalog product attribute controller
*
Expand Down Expand Up @@ -207,8 +209,7 @@ public function saveAction()

//validate attribute_code
if (isset($data['attribute_code'])) {
$validatorAttrCode = new Zend_Validate_Regex(['pattern' => '/^(?!event$)[a-z][a-z_0-9]{1,254}$/']);
if (!$validatorAttrCode->isValid($data['attribute_code'])) {
if (!v::regex('/^(?!event$)[a-z][a-z_0-9]{1,254}$/')->validate($data['attribute_code'])) {
$session->addError(
Mage::helper('catalog')->__('Attribute code is invalid. Please use only letters (a-z), numbers (0-9) or underscore(_) in this field, first character should be a letter. Do not use "event" for an attribute code.'),
);
Expand Down
4 changes: 3 additions & 1 deletion app/code/core/Mage/Adminhtml/controllers/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
* Index admin controller
*
Expand Down Expand Up @@ -220,7 +222,7 @@ public function forgotpasswordAction()
if ($this->_validateFormKey()) {
if (!empty($email)) {
// Validate received data to be an email address
if (Zend_Validate::is($email, 'EmailAddress')) {
if (v::email()->validate($email)) {
$collection = Mage::getResourceModel('admin/user_collection');
/** @var Mage_Admin_Model_Resource_User_Collection $collection */
$collection->addFieldToFilter('email', $email);
Expand Down
11 changes: 6 additions & 5 deletions app/code/core/Mage/Api/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
* Api model
*
Expand Down Expand Up @@ -365,25 +367,24 @@ protected function _getHelper($helperName)
* Validate user attribute values.
*
* @return array|true
* @throws Zend_Validate_Exception
*/
public function validate()
{
$errors = new ArrayObject();

if (!Zend_Validate::is($this->getUsername(), 'NotEmpty')) {
if (!v::stringType()->notEmpty()->validate($this->getUsername())) {
$errors->append($this->_getHelper('api')->__('User Name is required field.'));
}

if (!Zend_Validate::is($this->getFirstname(), 'NotEmpty')) {
if (!v::stringType()->notEmpty()->validate($this->getFirstname())) {
$errors->append($this->_getHelper('api')->__('First Name is required field.'));
}

if (!Zend_Validate::is($this->getLastname(), 'NotEmpty')) {
if (!v::stringType()->notEmpty()->validate($this->getLastname())) {
$errors->append($this->_getHelper('api')->__('Last Name is required field.'));
}

if (!Zend_Validate::is($this->getEmail(), 'EmailAddress')) {
if (!v::email()->validate($this->getEmail())) {
$errors->append($this->_getHelper('api')->__('Please enter a valid email.'));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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);
Comment on lines +122 to 123
Copy link

Copilot AI Oct 26, 2025

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 just empty($data['attribute_set_id']). While functionally equivalent (empty() checks both isset and truthiness), this changes the behavior subtly: empty() will return true for '0' and 0, 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.

Suggested change
if (empty($data['attribute_set_id'])) {
$this->_critical('Missing "attribute_set_id" in request.', Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
if (!isset($data['attribute_set_id']) || !is_numeric($data['attribute_set_id']) || (int)$data['attribute_set_id'] <= 0) {
$this->_critical('Missing or invalid "attribute_set_id" in request.', Mage_Api2_Model_Server::HTTP_BAD_REQUEST);

Copilot uses AI. Check for mistakes.
}
if (!isset($data['type_id']) || empty($data['type_id'])) {
if (empty($data['type_id'])) {
Copy link

Copilot AI Oct 26, 2025

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 just empty($data['attribute_set_id']). While functionally equivalent (empty() checks both isset and truthiness), this changes the behavior subtly: empty() will return true for '0' and 0, 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.

Copilot uses AI. Check for mistakes.
$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.');
}
Expand Down Expand Up @@ -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));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @method $this setQuoteItem(Mage_Sales_Model_Quote_Item $value)
* @method array|int getUserValue()
* @method $this setRequest(Varien_Object $value)
* @method $this setUserValue(array|int $value)
* @method $this setUserValue(array|int|null $value)
*/
class Mage_Catalog_Model_Product_Option_Type_Default extends Varien_Object
{
Expand Down
4 changes: 3 additions & 1 deletion app/code/core/Mage/Checkout/Model/Type/Onepage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
* One page checkout processing model
*
Expand Down Expand Up @@ -506,7 +508,7 @@ protected function _processValidateCustomer(Mage_Sales_Model_Quote_Address $addr
}
} elseif (self::METHOD_GUEST == $this->getQuote()->getCheckoutMethod()) {
$email = $address->getData('email');
if (!Zend_Validate::is($email, 'EmailAddress')) {
if (!v::email()->validate($this->getEmail())) {
return [
'error' => -1,
'message' => Mage::helper('checkout')->__('Invalid email address "%s"', $email),
Expand Down
8 changes: 5 additions & 3 deletions app/code/core/Mage/Contacts/controllers/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
* Contacts index controller
*
Expand Down Expand Up @@ -66,11 +68,11 @@ public function postAction()

// check data
$error = false;
if (!Zend_Validate::is(trim($post['name']), 'NotEmpty')) {
if (!v::stringType()->notEmpty()->validate(trim($post['name']))) {
$error = true;
} elseif (!Zend_Validate::is(trim($post['comment']), 'NotEmpty')) {
} elseif (!v::stringType()->notEmpty()->validate(trim($post['comment']))) {
$error = true;
} elseif (!Zend_Validate::is(trim($post['email']), 'EmailAddress')) {
} elseif (!v::email()->validate(trim($post['email']))) {
$error = true;
}

Expand Down
10 changes: 8 additions & 2 deletions app/code/core/Mage/Core/Model/Email/Template/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
* Template model
*
Expand Down Expand Up @@ -228,16 +230,20 @@ protected function _getCssFileContent($filename)
'_theme' => $theme,
],
);
$validator = new Zend_Validate_File_Extension('css');

if ($validator->isValid($filePath) && is_readable($filePath)) {
if ($this->validateFileExension('css', $filePath) && is_readable($filePath)) {
return (string) file_get_contents($filePath);
}

// If file can't be found, return empty string
return '';
}

public function validateFileExension(string $extension, string $filePath): bool
{
return v::extension($extension)->validate($filePath);
}

/**
* Accepts a path to a System Config setting that contains a comma-delimited list of files to load. Loads those
* files and then returns the concatenated content.
Expand Down
Loading