diff --git a/app/code/core/Mage/Admin/Model/User.php b/app/code/core/Mage/Admin/Model/User.php index 710683dfdda..edb9513824f 100644 --- a/app/code/core/Mage/Admin/Model/User.php +++ b/app/code/core/Mage/Admin/Model/User.php @@ -130,9 +130,9 @@ protected function _construct() protected function _beforeSave() { $data = [ - 'firstname' => $this->getFirstname(), - 'lastname' => $this->getLastname(), - 'email' => $this->getEmail(), + 'firstname' => trim((string) $this->getFirstname()), + 'lastname' => trim((string) $this->getLastname()), + 'email' => trim((string) $this->getEmail()), 'modified' => $this->_getDateNow(), 'extra' => serialize($this->getExtra()), ]; @@ -142,7 +142,7 @@ protected function _beforeSave() } if ($this->getUsername()) { - $data['username'] = $this->getUsername(); + $data['username'] = trim((string) $this->getUsername()); } if ($this->getNewPassword()) { diff --git a/app/code/core/Mage/Core/Controller/Request/Http.php b/app/code/core/Mage/Core/Controller/Request/Http.php index cd82106eda9..ca0cd5f1684 100644 --- a/app/code/core/Mage/Core/Controller/Request/Http.php +++ b/app/code/core/Mage/Core/Controller/Request/Http.php @@ -584,4 +584,30 @@ public function getInternallyForwarded() { return $this->_internallyForwarded; } + + /** + * Retrieve a parameter from request (GET/POST) and trim whitespace for string and array values. + * + * @param string $key + * @param mixed $default + * @return mixed + */ + public function getParam($key, $default = null) + { + // Get the parameter value from parent (Zend_Controller_Request_Http) + $value = parent::getParam($key, $default); + + // Trim whitespace for string values + if (is_string($value)) { + $value = trim($value); + } + + // For array values, trim each string element + if (is_array($value)) { + $value = array_map(function ($v) { + return is_string($v) ? trim($v) : $v; + }, $value); + } + return $value; + } } diff --git a/app/code/core/Mage/Sales/Model/Order/Address.php b/app/code/core/Mage/Sales/Model/Order/Address.php index cc22549276a..6373cad4cc8 100644 --- a/app/code/core/Mage/Sales/Model/Order/Address.php +++ b/app/code/core/Mage/Sales/Model/Order/Address.php @@ -122,11 +122,19 @@ public function getOrder() /** * Before object save manipulations + * Trim whitespace for all string data to prevent unwanted spaces on save * * @return $this */ protected function _beforeSave() { + // Trim all string fields before saving (for clean data storage) + foreach ($this->getData() as $key => $value) { + if (is_string($value)) { + $this->setData($key, trim($value)); + } + } + parent::_beforeSave(); if (!$this->getParentId() && $this->getOrder()) { diff --git a/app/code/core/Mage/Tag/Model/Resource/Tag.php b/app/code/core/Mage/Tag/Model/Resource/Tag.php index 7cff76d130c..5c31e2791f3 100644 --- a/app/code/core/Mage/Tag/Model/Resource/Tag.php +++ b/app/code/core/Mage/Tag/Model/Resource/Tag.php @@ -67,6 +67,9 @@ public function loadByName($model, $name) */ protected function _beforeSave(Mage_Core_Model_Abstract $object) { + // Trim whitespace for Tag name + $object->setName(trim($object->getName())); + if (!$object->getId() && $object->getStatus() == $object->getApprovedStatus()) { $searchTag = new Varien_Object(); $this->loadByName($searchTag, $object->getName()); diff --git a/app/code/core/Mage/Tax/Model/Calculation/Rate.php b/app/code/core/Mage/Tax/Model/Calculation/Rate.php index bf63df54929..dd394a6adf9 100644 --- a/app/code/core/Mage/Tax/Model/Calculation/Rate.php +++ b/app/code/core/Mage/Tax/Model/Calculation/Rate.php @@ -69,6 +69,15 @@ protected function _construct() */ protected function _beforeSave() { + // Trim whitespace for all relevant fields before validation and save + $this->setCode(trim((string) $this->getCode())); + $this->setTaxCountryId(trim((string) $this->getTaxCountryId())); + $this->setTaxRegionId(trim((string) $this->getTaxRegionId())); + $this->setTaxPostcode(trim((string) $this->getTaxPostcode())); + $this->setRate(trim((string) $this->getRate())); + $this->setZipFrom(trim((string) $this->getZipFrom())); + $this->setZipTo(trim((string) $this->getZipTo())); + if ($this->getCode() === '' || $this->getTaxCountryId() === '' || $this->getRate() === '' || $this->getZipIsRange() && ($this->getZipFrom() === '' || $this->getZipTo() === '') ) {