Skip to content

Fix TypeError when the type param is missing on the admin new product page - #318

Merged
rhoerr merged 1 commit into
mage-os:mainfrom
controlaltdelete-nl:fix/new-action-null-type-param
Aug 11, 2026
Merged

Fix TypeError when the type param is missing on the admin new product page#318
rhoerr merged 1 commit into
mage-os:mainfrom
controlaltdelete-nl:fix/new-action-null-type-param

Conversation

@michielgerritsen

@michielgerritsen michielgerritsen commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

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 .../module-catalog/Controller/Adminhtml/Product/NewAction.php on line 71
in .../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.

Fixed Issues

Fixes the fatal error above. No linked GitHub issue.

Manual testing scenarios

  1. Log into the admin panel.
  2. Visit admin/catalog/product/new/ (no type and no set in the URL).
    • Before: HTTP 500, TypeError in exception.log.
    • After: forwarded to the 404 / noroute page.
  3. Visit admin/catalog/product/new/?type[]=simple.
    • Before: HTTP 500, TypeError ... array given.
    • After: forwarded to the 404 / noroute page.
  4. Visit a regular admin/catalog/product/new/set/4/type/simple/ URL and confirm the new product form still loads.
  5. 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.

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit tests (Magento\Catalog\Test\Unit\Controller\Adminhtml\Product\NewActionTest::testExecuteWithoutTypeParam and ::testExecuteWithNonStringTypeParam, both fail with the reported TypeError without the fix)
  • All automated tests passed successfully (vendor/bin/phpunit -c dev/tests/unit/phpunit.xml.dist app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/NewActionTest.php)

Related Pull Requests

The same fix submitted upstream to Magento: magento/magento2#41105

Magento\Catalog\Controller\Adminhtml\Product\NewAction::execute() passes
the raw 'type' request param straight into
Magento\Framework\RegexValidator::validateParamRegex(), which is typed as
string. Opening admin/catalog/product/new without a type param makes
getParam() return null and the request dies with a TypeError instead of
forwarding to noroute. An array param (?type[]=simple) fails the same way.

Guard the call like Sales\Controller\Adminhtml\Order\Create\LoadBlock
already does, and forward to noroute for any non-string type.

@rhoerr rhoerr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rhoerr
rhoerr merged commit 4eb8b25 into mage-os:main Aug 11, 2026
7 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants