Skip to content

25668 Store code validation regex doesn't support uppercase letters #27248

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

Closed
Closed
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
9 changes: 6 additions & 3 deletions lib/internal/Magento/Framework/App/Config/Scope/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use Magento\Framework\Phrase;

/**
* Class Validator validates scope and scope code.
*
* @deprecated 100.2.0 Added in order to avoid backward incompatibility because class was moved to another directory.
* @see \Magento\Framework\App\Scope\Validator
*/
Expand All @@ -34,7 +36,7 @@ public function __construct(ScopeResolverPool $scopeResolverPool)
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function isValid($scope, $scopeCode = null)
{
Expand Down Expand Up @@ -73,6 +75,7 @@ public function isValid($scope, $scopeCode = null)

/**
* Validate scope code
*
* Throw exception if not valid.
*
* @param string $scopeCode
Expand All @@ -85,9 +88,9 @@ private function validateScopeCode($scopeCode)
throw new LocalizedException(new Phrase('A scope code is missing. Enter a code and try again.'));
}

if (!preg_match('/^[a-z]+[a-z0-9_]*$/', $scopeCode)) {
if (!preg_match('/^[a-zA-Z]+[a-zA-Z0-9_]*$/', $scopeCode)) {
throw new LocalizedException(new Phrase(
'The scope code can include only lowercase letters (a-z), numbers (0-9) and underscores (_). '
'The scope code can include only letters (a-z) and (A-Z), numbers (0-9) and underscores (_). '
. 'Also, the first character must be a letter.'
));
}
Expand Down
7 changes: 4 additions & 3 deletions lib/internal/Magento/Framework/App/Scope/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct(ScopeResolverPool $scopeResolverPool)
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function isValid($scope, $scopeCode = null)
{
Expand Down Expand Up @@ -71,6 +71,7 @@ public function isValid($scope, $scopeCode = null)

/**
* Validate scope code
*
* Throw exception if not valid.
*
* @param string $scopeCode
Expand All @@ -83,9 +84,9 @@ private function validateScopeCode($scopeCode)
throw new LocalizedException(new Phrase('A scope code is missing. Enter a code and try again.'));
}

if (!preg_match('/^[a-z]+[a-z0-9_]*$/', $scopeCode)) {
if (!preg_match('/^[a-zA-Z]+[a-zA-Z0-9_]*$/', $scopeCode)) {
throw new LocalizedException(new Phrase(
'The scope code can include only lowercase letters (a-z), numbers (0-9) and underscores (_). '
'The scope code can include only letters (a-z) and (A-Z), numbers (0-9) and underscores (_). '
. 'Also, the first character must be a letter.'
));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
namespace Magento\Framework\App\Test\Unit\Config\Scope;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Scope\Validator;
use Magento\Framework\App\ScopeInterface;
use Magento\Framework\App\ScopeResolverInterface;
use Magento\Framework\App\ScopeResolverPool;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\App\Scope\Validator;
use \PHPUnit_Framework_MockObject_MockObject as MockObject;
use PHPUnit_Framework_MockObject_MockObject as MockObject;

/**
* @deprecated As tested model class was moved to another directory,
Expand Down Expand Up @@ -100,7 +100,8 @@ public function testEmptyScopeCode()

/**
* @expectedException \Magento\Framework\Exception\LocalizedException
* @expectedExceptionMessage The scope code can include only lowercase letters (a-z), numbers (0-9) and underscores
* @expectedExceptionMessage The scope code can include only letters (a-z) and (A-Z),
* numbers (0-9) and underscores (_). Also, the first character must be a letter.
*/
public function testWrongScopeCodeFormat()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ public function testEmptyScopeCode()

/**
* @expectedException \Magento\Framework\Exception\LocalizedException
* @expectedExceptionMessage The scope code can include only lowercase letters (a-z), numbers (0-9) and underscores
* @expectedExceptionMessage The scope code can include only letters (a-z) and (A-Z),
* numbers (0-9) and underscores (_). Also, the first character must be a letter.
*/
public function testWrongScopeCodeFormat()
{
Expand Down