This issue is automatically created based on existing pull request: #41105: Fix TypeError when the type param is missing on the admin new product page
Description (*)
Opening the admin "New Product" page without a type request parameter throws a fatal TypeError instead of forwarding to noroute:
TypeError: Magento\Framework\RegexValidator::validateParamRegex(): Argument #1 ($params) must be of type string, null given,
called in .../Magento/Catalog/Controller/Adminhtml/Product/NewAction.php on line 71
in .../Magento/Framework/RegexValidator.php:43
NewAction::execute() passes the raw request param straight into RegexValidator::validateParamRegex(), which is declared as string $params. RequestInterface::getParam() returns null when the parameter is absent, so the request dies with a 500. The same happens for an array param (?type[]=simple), which produces array given.
Magento\Sales\Controller\Adminhtml\Order\Create\LoadBlock already guards its call to the same method; NewAction does not. This change applies the same guard and forwards to noroute for any non-string type, so the validation introduced in AC-7025 keeps working while an absent parameter no longer 500s.
Related Pull Requests
The same fix submitted to Mage-OS: mage-os/mageos-magento2#318
Fixed Issues (if relevant)
No linked GitHub issue; reported from a production exception.log.
Manual testing scenarios (*)
- Log into the admin panel.
- Visit
admin/catalog/product/new/ (no type and no set in the URL).
- Before: HTTP 500,
TypeError in var/log/exception.log.
- After: forwarded to the 404 /
noroute page.
- Visit
admin/catalog/product/new/?type[]=simple.
- Before: HTTP 500,
TypeError ... array given.
- After: forwarded to the 404 /
noroute page.
- Visit a regular
admin/catalog/product/new/set/4/type/simple/ URL and confirm the new product form still loads.
- Confirm the original protection still holds: a
type param containing layout-handle injection characters still forwards to noroute.
Questions or comments
The alternative fix would be widening RegexValidator::validateParamRegex() to accept ?string. That changes a public method signature on a non-final framework class, so I kept the change in the caller instead, matching the existing LoadBlock pattern. Happy to switch approaches if you prefer the framework-level fix.
Contribution checklist (*)
This issue is automatically created based on existing pull request: #41105: Fix TypeError when the type param is missing on the admin new product page
Description (*)
Opening the admin "New Product" page without a
typerequest parameter throws a fatalTypeErrorinstead of forwarding tonoroute:NewAction::execute()passes the raw request param straight intoRegexValidator::validateParamRegex(), which is declared asstring $params.RequestInterface::getParam()returnsnullwhen the parameter is absent, so the request dies with a 500. The same happens for an array param (?type[]=simple), which producesarray given.Magento\Sales\Controller\Adminhtml\Order\Create\LoadBlockalready guards its call to the same method;NewActiondoes not. This change applies the same guard and forwards tonoroutefor any non-stringtype, so the validation introduced in AC-7025 keeps working while an absent parameter no longer 500s.Related Pull Requests
The same fix submitted to Mage-OS: mage-os/mageos-magento2#318
Fixed Issues (if relevant)
No linked GitHub issue; reported from a production
exception.log.Manual testing scenarios (*)
admin/catalog/product/new/(notypeand nosetin the URL).TypeErrorinvar/log/exception.log.noroutepage.admin/catalog/product/new/?type[]=simple.TypeError ... array given.noroutepage.admin/catalog/product/new/set/4/type/simple/URL and confirm the new product form still loads.typeparam containing layout-handle injection characters still forwards tonoroute.Questions or comments
The alternative fix would be widening
RegexValidator::validateParamRegex()to accept?string. That changes a public method signature on a non-final framework class, so I kept the change in the caller instead, matching the existingLoadBlockpattern. Happy to switch approaches if you prefer the framework-level fix.Contribution checklist (*)
Magento\Catalog\Test\Unit\Controller\Adminhtml\Product\NewActionTest::testExecuteWithoutTypeParamand::testExecuteWithNonStringTypeParam, both reproduce the reportedTypeErrorwithout the fix)vendor/bin/phpunit -c dev/tests/unit/phpunit.xml.dist app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/NewActionTest.php)