Skip to content

Commit 13c070e

Browse files
Merge pull request #8074 from magento-cia/cia-2.4.7-beta1-develop-bugfixes-01132023
cia-2.4.7-beta1-develop-bugfixes-01132023
2 parents 913cbf9 + 7b1163f commit 13c070e

File tree

10 files changed

+301
-73
lines changed

10 files changed

+301
-73
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/NewAction.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@
44
* Copyright © Magento, Inc. All rights reserved.
55
* See COPYING.txt for license details.
66
*/
7+
declare(strict_types=1);
8+
79
namespace Magento\Catalog\Controller\Adminhtml\Product;
810

9-
use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
10-
use Magento\Backend\App\Action;
1111
use Magento\Catalog\Controller\Adminhtml\Product;
12+
use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
1213
use Magento\Framework\App\ObjectManager;
14+
use Magento\Framework\RegexValidator;
1315

1416
class NewAction extends \Magento\Catalog\Controller\Adminhtml\Product implements HttpGetActionInterface
1517
{
1618
/**
1719
* @var Initialization\StockDataFilter
1820
* @deprecated 101.0.0
21+
* @see Initialization\StockDataFilter
1922
*/
2023
protected $stockFilter;
2124

@@ -30,23 +33,32 @@ class NewAction extends \Magento\Catalog\Controller\Adminhtml\Product implements
3033
protected $resultForwardFactory;
3134

3235
/**
33-
* @param Action\Context $context
36+
* @var RegexValidator
37+
*/
38+
private RegexValidator $regexValidator;
39+
40+
/**
41+
* @param Context $context
3442
* @param Builder $productBuilder
3543
* @param Initialization\StockDataFilter $stockFilter
3644
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
3745
* @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory
46+
* @param RegexValidator|null $regexValidator
3847
*/
3948
public function __construct(
4049
\Magento\Backend\App\Action\Context $context,
4150
Product\Builder $productBuilder,
4251
Initialization\StockDataFilter $stockFilter,
4352
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
44-
\Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory
53+
\Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory,
54+
RegexValidator $regexValidator = null
4555
) {
4656
$this->stockFilter = $stockFilter;
4757
parent::__construct($context, $productBuilder);
4858
$this->resultPageFactory = $resultPageFactory;
4959
$this->resultForwardFactory = $resultForwardFactory;
60+
$this->regexValidator = $regexValidator
61+
?: ObjectManager::getInstance()->get(RegexValidator::class);
5062
}
5163

5264
/**
@@ -56,6 +68,11 @@ public function __construct(
5668
*/
5769
public function execute()
5870
{
71+
$typeId = $this->getRequest()->getParam('type');
72+
if (!$this->regexValidator->validateParamRegex($typeId)) {
73+
return $this->resultForwardFactory->create()->forward('noroute');
74+
}
75+
5976
if (!$this->getRequest()->getParam('set')) {
6077
return $this->resultForwardFactory->create()->forward('noroute');
6178
}

app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/NewActionTest.php

100644100755
Lines changed: 77 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
use Magento\Catalog\Controller\Adminhtml\Product\NewAction;
1717
use Magento\Catalog\Model\Product;
1818
use Magento\Catalog\Test\Unit\Controller\Adminhtml\ProductTest;
19+
use Magento\Framework\RegexValidator;
20+
use Magento\Framework\Validator\Regex;
21+
use Magento\Framework\Validator\RegexFactory;
1922
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
2023
use Magento\Framework\View\Result\PageFactory;
2124
use PHPUnit\Framework\MockObject\MockObject;
@@ -42,6 +45,26 @@ class NewActionTest extends ProductTest
4245
*/
4346
protected $initializationHelper;
4447

48+
/**
49+
* @var RegexValidator|MockObject
50+
*/
51+
private $regexValidator;
52+
53+
/**
54+
* @var RegexFactory
55+
*/
56+
private $regexValidatorFactoryMock;
57+
58+
/**
59+
* @var Regex|MockObject
60+
*/
61+
private $regexValidatorMock;
62+
63+
/**
64+
* @var ForwardFactory&MockObject|MockObject
65+
*/
66+
private $resultForwardFactory;
67+
4568
protected function setUp(): void
4669
{
4770
$this->productBuilder = $this->createPartialMock(
@@ -63,37 +86,78 @@ protected function setUp(): void
6386
->disableOriginalConstructor()
6487
->setMethods(['create'])
6588
->getMock();
66-
$resultPageFactory->expects($this->atLeastOnce())
67-
->method('create')
68-
->willReturn($this->resultPage);
6989

7090
$this->resultForward = $this->getMockBuilder(Forward::class)
7191
->disableOriginalConstructor()
7292
->getMock();
73-
$resultForwardFactory = $this->getMockBuilder(ForwardFactory::class)
93+
$this->resultForwardFactory = $this->getMockBuilder(ForwardFactory::class)
94+
->disableOriginalConstructor()
95+
->onlyMethods(['create'])
96+
->getMock();
97+
98+
$this->regexValidatorFactoryMock = $this->getMockBuilder(RegexFactory::class)
7499
->disableOriginalConstructor()
75100
->setMethods(['create'])
76101
->getMock();
77-
$resultForwardFactory->expects($this->any())
78-
->method('create')
79-
->willReturn($this->resultForward);
102+
$this->regexValidatorMock = $this->createMock(Regex::class);
103+
$this->regexValidatorFactoryMock->method('create')
104+
->willReturn($this->regexValidatorMock);
80105

106+
$this->regexValidator = new regexValidator($this->regexValidatorFactoryMock);
81107
$this->action = (new ObjectManager($this))->getObject(
82108
NewAction::class,
83109
[
84110
'context' => $this->initContext(),
85111
'productBuilder' => $this->productBuilder,
86112
'resultPageFactory' => $resultPageFactory,
87-
'resultForwardFactory' => $resultForwardFactory,
113+
'resultForwardFactory' => $this->resultForwardFactory,
114+
'regexValidator' => $this->regexValidator,
88115
]
89116
);
90117
}
91118

92-
public function testExecute()
119+
/**
120+
* Test execute method input validation.
121+
*
122+
* @param string $value
123+
* @param bool $exceptionThrown
124+
* @dataProvider validationCases
125+
*/
126+
public function testExecute(string $value, bool $exceptionThrown): void
127+
{
128+
if ($exceptionThrown) {
129+
$this->action->getRequest()->expects($this->any())
130+
->method('getParam')
131+
->willReturn($value);
132+
$this->resultForwardFactory->expects($this->any())
133+
->method('create')
134+
->willReturn($this->resultForward);
135+
$this->resultForward->expects($this->once())
136+
->method('forward')
137+
->with('noroute')
138+
->willReturn(true);
139+
$this->assertTrue($this->action->execute());
140+
} else {
141+
$this->action->getRequest()->expects($this->any())->method('getParam')->willReturn($value);
142+
$this->regexValidatorMock->expects($this->any())
143+
->method('isValid')
144+
->with($value)
145+
->willReturn(true);
146+
147+
$this->assertEquals(true, $this->regexValidator->validateParamRegex($value));
148+
}
149+
}
150+
151+
/**
152+
* Validation cases.
153+
*
154+
* @return array
155+
*/
156+
public function validationCases(): array
93157
{
94-
$this->action->getRequest()->expects($this->any())->method('getParam')->willReturn(true);
95-
$this->action->getRequest()->expects($this->any())->method('getFullActionName')
96-
->willReturn('catalog_product_new');
97-
$this->action->execute();
158+
return [
159+
'execute-with-exception' => ['simple\' and true()]|*[self%3a%3ahandle%20or%20self%3a%3alayout',true],
160+
'execute-without-exception' => ['catalog_product_new',false]
161+
];
98162
}
99163
}

app/code/Magento/Catalog/i18n/en_US.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,4 +819,5 @@ Details,Details
819819
"Failed to retrieve product links for ""%1""","Failed to retrieve product links for ""%1"""
820820
"The linked product SKU is invalid. Verify the data and try again.","The linked product SKU is invalid. Verify the data and try again."
821821
"The linked products data is invalid. Verify the data and try again.","The linked products data is invalid. Verify the data and try again."
822+
"The url has invalid characters. Please correct and try again.","The url has invalid characters. Please correct and try again."
822823

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
*/
4949
class Product extends AbstractEntity
5050
{
51+
private const COL_NAME_FORMAT = '/[\x00-\x1F\x7F]/';
5152
private const DEFAULT_GLOBAL_MULTIPLE_VALUE_SEPARATOR = ',';
5253
public const CONFIG_KEY_PRODUCT_TYPES = 'global/importexport/import_product_types';
5354

@@ -1624,6 +1625,10 @@ protected function _saveProducts()
16241625
// the bunch of products will pass for the event with url_key column.
16251626
$bunch[$rowNum][self::URL_KEY] = $rowData[self::URL_KEY] = $urlKey;
16261627
}
1628+
if (!empty($rowData[self::COL_NAME])) {
1629+
// remove null byte character
1630+
$rowData[self::COL_NAME] = preg_replace(self::COL_NAME_FORMAT, '', $rowData[self::COL_NAME]);
1631+
}
16271632
$rowSku = $rowData[self::COL_SKU];
16281633
if (null === $rowSku) {
16291634
$this->getErrorAggregator()->addRowToSkip($rowNum);

app/code/Magento/Checkout/Model/ShippingInformationManagement.php

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Checkout\Model;
89

@@ -39,60 +40,62 @@ class ShippingInformationManagement implements ShippingInformationManagementInte
3940
/**
4041
* @var PaymentMethodManagementInterface
4142
*/
42-
protected $paymentMethodManagement;
43+
protected PaymentMethodManagementInterface $paymentMethodManagement;
4344

4445
/**
4546
* @var PaymentDetailsFactory
4647
*/
47-
protected $paymentDetailsFactory;
48+
protected PaymentDetailsFactory $paymentDetailsFactory;
4849

4950
/**
5051
* @var CartTotalRepositoryInterface
5152
*/
52-
protected $cartTotalsRepository;
53+
protected CartTotalRepositoryInterface $cartTotalsRepository;
5354

5455
/**
5556
* @var CartRepositoryInterface
5657
*/
57-
protected $quoteRepository;
58-
58+
protected CartRepositoryInterface $quoteRepository;
5959
/**
6060
* @var Logger
6161
*/
62-
protected $logger;
62+
protected Logger $logger;
6363

6464
/**
6565
* @var QuoteAddressValidator
6666
*/
67-
protected $addressValidator;
67+
protected QuoteAddressValidator $addressValidator;
6868

6969
/**
7070
* @var AddressRepositoryInterface
7171
* @deprecated 100.2.0
72+
* @see AddressRepositoryInterface
7273
*/
73-
protected $addressRepository;
74+
protected AddressRepositoryInterface $addressRepository;
7475

7576
/**
7677
* @var ScopeConfigInterface
7778
* @deprecated 100.2.0
79+
* @see ScopeConfigInterface
7880
*/
79-
protected $scopeConfig;
81+
protected ScopeConfigInterface $scopeConfig;
8082

8183
/**
8284
* @var TotalsCollector
8385
* @deprecated 100.2.0
86+
* @see TotalsCollector
8487
*/
85-
protected $totalsCollector;
88+
protected TotalsCollector $totalsCollector;
8689

8790
/**
8891
* @var CartExtensionFactory
8992
*/
90-
private $cartExtensionFactory;
93+
private CartExtensionFactory $cartExtensionFactory;
9194

9295
/**
9396
* @var ShippingAssignmentFactory
9497
*/
95-
protected $shippingAssignmentFactory;
98+
protected ShippingAssignmentFactory $shippingAssignmentFactory;
9699

97100
/**
98101
* @var ShippingFactory
@@ -262,8 +265,11 @@ protected function validateQuote(Quote $quote): void
262265
* @param string $method
263266
* @return CartInterface
264267
*/
265-
private function prepareShippingAssignment(CartInterface $quote, AddressInterface $address, $method): CartInterface
266-
{
268+
private function prepareShippingAssignment(
269+
CartInterface $quote,
270+
AddressInterface $address,
271+
string $method
272+
): CartInterface {
267273
$cartExtension = $quote->getExtensionAttributes();
268274
if ($cartExtension === null) {
269275
$cartExtension = $this->cartExtensionFactory->create();

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Quote\Model;
89

10+
use Magento\Framework\App\ObjectManager;
911
use Magento\Framework\Exception\InputException;
10-
use Magento\Quote\Model\Quote\Address\BillingAddressPersister;
11-
use Psr\Log\LoggerInterface as Logger;
1212
use Magento\Quote\Api\BillingAddressManagementInterface;
13-
use Magento\Framework\App\ObjectManager;
13+
use Magento\Quote\Api\Data\AddressInterface;
14+
use Psr\Log\LoggerInterface as Logger;
1415

1516
/**
1617
* Quote billing address write service object.
@@ -25,14 +26,14 @@ class BillingAddressManagement implements BillingAddressManagementInterface
2526
protected $addressValidator;
2627

2728
/**
28-
* Logger.
29+
* Logger object.
2930
*
3031
* @var Logger
3132
*/
3233
protected $logger;
3334

3435
/**
35-
* Quote repository.
36+
* Quote repository object.
3637
*
3738
* @var \Magento\Quote\Api\CartRepositoryInterface
3839
*/
@@ -72,10 +73,14 @@ public function __construct(
7273
* @inheritdoc
7374
* @SuppressWarnings(PHPMD.NPathComplexity)
7475
*/
75-
public function assign($cartId, \Magento\Quote\Api\Data\AddressInterface $address, $useForShipping = false)
76+
public function assign($cartId, AddressInterface $address, $useForShipping = false)
7677
{
7778
/** @var \Magento\Quote\Model\Quote $quote */
7879
$quote = $this->quoteRepository->getActive($cartId);
80+
81+
// validate the address
82+
$this->addressValidator->validateWithExistingAddress($quote, $address);
83+
7984
$address->setCustomerId($quote->getCustomerId());
8085
$quote->removeAddress($quote->getBillingAddress()->getId());
8186
$quote->setBillingAddress($address);
@@ -104,6 +109,7 @@ public function get($cartId)
104109
*
105110
* @return \Magento\Quote\Model\ShippingAddressAssignment
106111
* @deprecated 101.0.0
112+
* @see \Magento\Quote\Model\ShippingAddressAssignment
107113
*/
108114
private function getShippingAddressAssignment()
109115
{

0 commit comments

Comments
 (0)