Skip to content

Commit 2ceeea4

Browse files
committed
MC-40538: When entering example.com/0 into browser the homepage is shown (example.com)
1 parent 7cdf8bd commit 2ceeea4

File tree

8 files changed

+46
-52
lines changed

8 files changed

+46
-52
lines changed

app/code/Magento/Customer/Model/Address/AbstractAddress.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class AbstractAddress extends AbstractExtensibleModel implements AddressModelInt
140140
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
141141
* @param array $data
142142
* @param CompositeValidator $compositeValidator
143-
*
143+
* @param \Magento\Framework\Validator\ValidatorInterface|null $modelValidator
144144
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
145145
*/
146146
public function __construct(
@@ -160,7 +160,8 @@ public function __construct(
160160
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
161161
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
162162
array $data = [],
163-
CompositeValidator $compositeValidator = null
163+
CompositeValidator $compositeValidator = null,
164+
?\Magento\Framework\Validator\ValidatorInterface $modelValidator = null
164165
) {
165166
$this->_directoryData = $directoryData;
166167
$data = $this->_implodeArrayField($data);
@@ -174,14 +175,16 @@ public function __construct(
174175
$this->dataObjectHelper = $dataObjectHelper;
175176
$this->compositeValidator = $compositeValidator ?: ObjectManager::getInstance()
176177
->get(CompositeValidator::class);
178+
177179
parent::__construct(
178180
$context,
179181
$registry,
180182
$extensionFactory,
181183
$customAttributeFactory,
182184
$resource,
183185
$resourceCollection,
184-
$data
186+
$data,
187+
$modelValidator
185188
);
186189
}
187190

app/code/Magento/Quote/Model/Quote/Address.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Customer\Api\Data\AddressInterfaceFactory;
1111
use Magento\Customer\Api\Data\RegionInterfaceFactory;
1212
use Magento\Customer\Model\Address\AbstractAddress;
13+
use Magento\Customer\Model\Address\CompositeValidator;
1314
use Magento\Customer\Model\Address\Mapper;
1415
use Magento\Directory\Helper\Data;
1516
use Magento\Directory\Model\CountryFactory;
@@ -334,7 +335,7 @@ class Address extends AbstractAddress implements
334335
* @param array $data
335336
* @param Json $serializer
336337
* @param StoreManagerInterface $storeManager
337-
*
338+
* @param CompositeValidator $compositeValidator
338339
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
339340
*/
340341
public function __construct(
@@ -371,7 +372,8 @@ public function __construct(
371372
AbstractDb $resourceCollection = null,
372373
array $data = [],
373374
Json $serializer = null,
374-
StoreManagerInterface $storeManager = null
375+
StoreManagerInterface $storeManager = null,
376+
CompositeValidator $compositeValidator = null
375377
) {
376378
$this->_scopeConfig = $scopeConfig;
377379
$this->_addressItemFactory = $addressItemFactory;
@@ -392,6 +394,7 @@ public function __construct(
392394
$this->totalsReader = $totalsReader;
393395
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class);
394396
$this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);
397+
395398
parent::__construct(
396399
$context,
397400
$registry,
@@ -408,7 +411,9 @@ public function __construct(
408411
$dataObjectHelper,
409412
$resource,
410413
$resourceCollection,
411-
$data
414+
$data,
415+
$compositeValidator,
416+
$this->validator
412417
);
413418
}
414419

@@ -1422,14 +1427,6 @@ public function getAllBaseTotalAmounts()
14221427

14231428
/******************************* End Total Collector Interface *******************************************/
14241429

1425-
/**
1426-
* @inheritdoc
1427-
*/
1428-
protected function _getValidationRulesBeforeSave()
1429-
{
1430-
return $this->validator;
1431-
}
1432-
14331430
/**
14341431
* @inheritdoc
14351432
*/

app/code/Magento/Store/App/Request/StorePathInfoValidator.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Store\Api\StoreRepositoryInterface;
1515
use Magento\Store\Model\Store;
1616
use Magento\Store\Model\StoreIsInactiveException;
17+
use Magento\Store\Model\Validation\StoreCodeValidator;
1718

1819
/**
1920
* Gets the store from the path if valid
@@ -37,19 +38,27 @@ class StorePathInfoValidator
3738
*/
3839
private $pathInfo;
3940

41+
/**
42+
* @var StoreCodeValidator
43+
*/
44+
private $storeCodeValidator;
45+
4046
/**
4147
* @param ScopeConfigInterface $config
4248
* @param StoreRepositoryInterface $storeRepository
4349
* @param PathInfo $pathInfo
50+
* @param StoreCodeValidator $storeCodeValidator
4451
*/
4552
public function __construct(
4653
ScopeConfigInterface $config,
4754
StoreRepositoryInterface $storeRepository,
48-
PathInfo $pathInfo
55+
PathInfo $pathInfo,
56+
StoreCodeValidator $storeCodeValidator
4957
) {
5058
$this->config = $config;
5159
$this->storeRepository = $storeRepository;
5260
$this->pathInfo = $pathInfo;
61+
$this->storeCodeValidator = $storeCodeValidator;
5362
}
5463

5564
/**
@@ -70,7 +79,7 @@ public function getValidStoreCode(Http $request, string $pathInfo = '') : ?strin
7079
$pathInfo = $this->pathInfo->getPathInfo($request->getRequestUri(), $request->getBaseUrl());
7180
}
7281
$storeCode = $this->getStoreCode($pathInfo);
73-
if (empty($storeCode) || $storeCode === Store::ADMIN_CODE) {
82+
if (empty($storeCode) || $storeCode === Store::ADMIN_CODE || !$this->storeCodeValidator->isValid($storeCode)) {
7483
return null;
7584
}
7685

app/code/Magento/Store/Model/Store.php

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -332,11 +332,6 @@ class Store extends AbstractExtensibleModel implements
332332
*/
333333
private $pillPut;
334334

335-
/**
336-
* @var Validation\StoreValidator
337-
*/
338-
private $modelValidator;
339-
340335
/**
341336
* @param \Magento\Framework\Model\Context $context
342337
* @param \Magento\Framework\Registry $registry
@@ -394,7 +389,7 @@ public function __construct(
394389
array $data = [],
395390
\Magento\Framework\Event\ManagerInterface $eventManager = null,
396391
\Magento\Framework\MessageQueue\PoisonPill\PoisonPillPutInterface $pillPut = null,
397-
?\Magento\Store\Model\Validation\StoreValidator $modelValidator = null
392+
?\Magento\Framework\Validator\ValidatorInterface $modelValidator = null
398393
) {
399394
$this->_coreFileStorageDatabase = $coreFileStorageDatabase;
400395
$this->_config = $config;
@@ -417,16 +412,16 @@ public function __construct(
417412
->get(\Magento\Framework\Event\ManagerInterface::class);
418413
$this->pillPut = $pillPut ?: \Magento\Framework\App\ObjectManager::getInstance()
419414
->get(\Magento\Framework\MessageQueue\PoisonPill\PoisonPillPutInterface::class);
420-
$this->modelValidator = $modelValidator ?? \Magento\Framework\App\ObjectManager::getInstance()
421-
->get(\Magento\Store\Model\Validation\StoreValidator::class);
415+
422416
parent::__construct(
423417
$context,
424418
$registry,
425419
$extensionFactory,
426420
$customAttributeFactory,
427421
$resource,
428422
$resourceCollection,
429-
$data
423+
$data,
424+
$modelValidator
430425
);
431426
}
432427

@@ -479,14 +474,6 @@ protected function _getSession()
479474
return $this->_session;
480475
}
481476

482-
/**
483-
* @inheritDoc
484-
*/
485-
protected function _getValidationRulesBeforeSave()
486-
{
487-
return $this->modelValidator;
488-
}
489-
490477
/**
491478
* Loading store data
492479
*

app/code/Magento/Store/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
<argument name="session" xsi:type="object" shared="false">Magento\Framework\Session\Generic\Proxy</argument>
9898
<argument name="isCustomEntryPoint" xsi:type="init_parameter">Magento\Store\Model\Store::CUSTOM_ENTRY_POINT_PARAM</argument>
9999
<argument name="url" xsi:type="object" shared="false">Magento\Framework\UrlInterface</argument>
100+
<argument name="modelValidator" xsi:type="object">Magento\Store\Model\Validation\StoreValidator</argument>
100101
</arguments>
101102
</type>
102103
<type name="Magento\Store\Model\StoreManager">

app/code/Magento/Tax/Model/Calculation/Rule.php

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ class Rule extends \Magento\Framework\Model\AbstractExtensibleModel implements T
4343
*/
4444
protected $_calculation;
4545

46-
/**
47-
* @var \Magento\Tax\Model\Calculation\Rule\Validator
48-
*/
49-
protected $validator;
50-
5146
/**
5247
* Name of object id field
5348
*
@@ -81,15 +76,15 @@ public function __construct(
8176
array $data = []
8277
) {
8378
$this->_calculation = $calculation;
84-
$this->validator = $validator;
8579
parent::__construct(
8680
$context,
8781
$registry,
8882
$extensionFactory,
8983
$customAttributeFactory,
9084
$resource,
9185
$resourceCollection,
92-
$data
86+
$data,
87+
$validator
9388
);
9489
$this->_init(\Magento\Tax\Model\ResourceModel\Calculation\Rule::class);
9590
$this->_taxClass = $taxClass;
@@ -280,14 +275,6 @@ protected function _getUniqueValues($values)
280275
return array_values(array_unique($values));
281276
}
282277

283-
/**
284-
* {@inheritdoc}
285-
*/
286-
protected function _getValidationRulesBeforeSave()
287-
{
288-
return $this->validator;
289-
}
290-
291278
/**
292279
* Set tax rule code
293280
*

lib/internal/Magento/Framework/Model/AbstractExtensibleModel.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ abstract class AbstractExtensibleModel extends AbstractModel implements
5555
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
5656
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
5757
* @param array $data
58+
* @param \Magento\Framework\Validator\ValidatorInterface|null $modelValidator
5859
*/
5960
public function __construct(
6061
\Magento\Framework\Model\Context $context,
@@ -63,12 +64,13 @@ public function __construct(
6364
AttributeValueFactory $customAttributeFactory,
6465
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
6566
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
66-
array $data = []
67+
array $data = [],
68+
?\Magento\Framework\Validator\ValidatorInterface $modelValidator = null
6769
) {
6870
$this->extensionAttributesFactory = $extensionFactory;
6971
$this->customAttributeFactory = $customAttributeFactory;
7072
$data = $this->filterCustomAttributes($data);
71-
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
73+
parent::__construct($context, $registry, $resource, $resourceCollection, $data, $modelValidator);
7274
if (isset($data['id'])) {
7375
$this->setId($data['id']);
7476
}

lib/internal/Magento/Framework/Model/AbstractModel.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,19 +163,26 @@ abstract class AbstractModel extends \Magento\Framework\DataObject
163163
*/
164164
protected $storedData = [];
165165

166+
/**
167+
* @var \Magento\Framework\Validator\ValidatorInterface|null
168+
*/
169+
private $modelValidator;
170+
166171
/**
167172
* @param \Magento\Framework\Model\Context $context
168173
* @param \Magento\Framework\Registry $registry
169174
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
170175
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
171176
* @param array $data
177+
* @param \Magento\Framework\Validator\ValidatorInterface|null $modelValidator
172178
*/
173179
public function __construct(
174180
\Magento\Framework\Model\Context $context,
175181
\Magento\Framework\Registry $registry,
176182
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
177183
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
178-
array $data = []
184+
array $data = [],
185+
?\Magento\Framework\Validator\ValidatorInterface $modelValidator = null
179186
) {
180187
$this->_registry = $registry;
181188
$this->_appState = $context->getAppState();
@@ -185,6 +192,7 @@ public function __construct(
185192
$this->_resourceCollection = $resourceCollection;
186193
$this->_logger = $context->getLogger();
187194
$this->_actionValidator = $context->getActionValidator();
195+
$this->modelValidator = $modelValidator;
188196

189197
if (method_exists($this->_resource, 'getIdFieldName')
190198
|| $this->_resource instanceof \Magento\Framework\DataObject
@@ -775,7 +783,7 @@ protected function _createValidatorBeforeSave()
775783
*/
776784
protected function _getValidationRulesBeforeSave()
777785
{
778-
return null;
786+
return $this->modelValidator;
779787
}
780788

781789
/**

0 commit comments

Comments
 (0)