Skip to content
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

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

Merged
merged 2 commits into from
Nov 6, 2017
Merged
Changes from 1 commit
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
8 changes: 4 additions & 4 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 @@ -463,10 +463,10 @@ 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-zA-Z]+[a-z0-9_]*$/');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This expression will not allow code with uppercase letter after number or underscore (e.g. a1A). Instead of modifying regexp it's better to apply modifier i (PCRE_CASELESS) to make case-insensitive comparison.

$storeCodeRule->setMessage(
__(
'The store code may contain only letters (a-z), numbers (0-9) or underscore (_),'
'The store code may contain only letters (a-zA-Z), numbers (0-9) or underscore (_),'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not modify the description as this will break existed translations (will be backward incompatible change). As string does not say "lowercase letters" it is also applicable for updated implementation

. ' and the first character must be a letter.'
),
\Zend_Validate_Regex::NOT_MATCH
Expand Down