Skip to content

[backport 2.1] Magento 2 Store Code validation regex: doesn't support uppercase letters in store code #12040

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions app/code/Magento/Store/Model/ResourceModel/Website.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function readAllWebsites()
->select()
->from($this->getTable('store_website'));

foreach($this->getConnection()->fetchAll($select) as $websiteData) {
foreach ($this->getConnection()->fetchAll($select) as $websiteData) {
$websites[$websiteData['code']] = $websiteData;
}

Expand All @@ -63,7 +63,7 @@ public function readAllWebsites()
*/
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
{
if (!preg_match('/^[a-z]+[a-z0-9_]*$/', $object->getCode())) {
if (!preg_match('/^[a-z]+[a-z0-9_]*$/i', $object->getCode())) {
throw new \Magento\Framework\Exception\LocalizedException(
__(
'Website code may only contain letters (a-z), numbers (0-9) or underscore (_),'
Expand Down
6 changes: 3 additions & 3 deletions app/code/Magento/Store/Model/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
use Magento\Framework\App\Http\Context;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\App\ScopeInterface as AppScopeInterface;
use Magento\Framework\Filesystem;
use Magento\Framework\DataObject\IdentityInterface;
use Magento\Framework\Url\ScopeInterface as UrlScopeInterface;
use Magento\Framework\Filesystem;
use Magento\Framework\Model\AbstractExtensibleModel;
use Magento\Framework\Url\ScopeInterface as UrlScopeInterface;
use Magento\Framework\UrlInterface;
use Magento\Store\Api\Data\StoreInterface;

Expand Down Expand Up @@ -459,7 +459,7 @@ protected function _getValidationRulesBeforeSave()
$storeLabelRule->setMessage(__('Name is required'), \Zend_Validate_NotEmpty::IS_EMPTY);
$validator->addRule($storeLabelRule, 'name');

$storeCodeRule = new \Zend_Validate_Regex('/^[a-z]+[a-z0-9_]*$/');
$storeCodeRule = new \Zend_Validate_Regex('/^[a-z]+[a-z0-9_]*$/i');
$storeCodeRule->setMessage(
__(
'The store code may contain only letters (a-z), numbers (0-9) or underscore (_),'
Expand Down