diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/NewAction.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/NewAction.php index dd55df63c51..81b5d71bff1 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/NewAction.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/NewAction.php @@ -68,7 +68,7 @@ public function __construct( public function execute() { $typeId = $this->getRequest()->getParam('type'); - if (!$this->regexValidator->validateParamRegex($typeId)) { + if ($typeId !== null && (!is_string($typeId) || !$this->regexValidator->validateParamRegex($typeId))) { return $this->resultForwardFactory->create()->forward('noroute'); } diff --git a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/NewActionTest.php b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/NewActionTest.php index 5018f233aab..601c7b9bec6 100755 --- a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/NewActionTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/NewActionTest.php @@ -132,6 +132,36 @@ public function testExecute(string $value, bool $exceptionThrown): void } } + /** + * Test execute method when the type parameter is absent from the request. + */ + public function testExecuteWithoutTypeParam(): void + { + $this->action->getRequest()->method('getParam')->willReturn(null); + $this->resultForwardFactory->method('create')->willReturn($this->resultForward); + $this->resultForward->expects($this->once()) + ->method('forward') + ->with('noroute') + ->willReturn(true); + + $this->assertTrue($this->action->execute()); + } + + /** + * Test execute method when the type parameter is not a string. + */ + public function testExecuteWithNonStringTypeParam(): void + { + $this->action->getRequest()->method('getParam')->willReturn(['simple']); + $this->resultForwardFactory->method('create')->willReturn($this->resultForward); + $this->resultForward->expects($this->once()) + ->method('forward') + ->with('noroute') + ->willReturn(true); + + $this->assertTrue($this->action->execute()); + } + /** * Validation cases. *