Fix #46730: Prevent crash when format parameter is invalid#46790
Fix #46730: Prevent crash when format parameter is invalid#46790VaishnaviSidral wants to merge 2 commits intojoomla:5.4-devfrom
Conversation
|
I have tested this item ✅ successfully on e355131 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/46790. |
|
I have tested this item ✅ successfully on e355131 Changes:
This resolves the crash when visiting URLs with empty format parameters (e.g., This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/46790. |
|
@VaishnaviSidral this pull request is absolutely useless if you dont spend the 2 minutes describing what it is, what it does, and how to test it. There was a reason you were asked those questions when you created the pull request - it wasnt just for fun. Please edit the description of this pull request to preovide the missing information otherwise this will have to be closed
|
|
This look like a workaround instead of proper fix fix. From what I see by looking at the code around, we should have a concrete document object created (Html, Raw...). So I think the fix would be adding a check here https://github.com/joomla/joomla-cms/blob/5.4-dev/libraries/src/Document/Factory.php#L40, in case $type is empty, set it to html (from everywhere, we use html as default format if it is not passed) |
|
I have tested this item ✅ successfully on e355131 By defaulting $type to an empty string instead of null, it avoids the TypeError in the exception handler. This allows the framework to properly fall back to the HTML renderer and display the correct 404 error page instead of crashing with HTTP 500. Tested using an invalid format parameter — behavior now matches the expected graceful error handling. No documentation changes required. This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/46790. |

Pull Request for Issue #46730 .
Summary of Changes
Changed the default value of
Document::$_typefromnullto an empty string.When an invalid or cleaned
formatparameter results in an empty output format, the document type remains unset (null). This causes aTypeErrorlater when the exception handler attempts to resolve a renderer using a non-string value.By defaulting the type to an empty string instead of
null, Joomla correctly throws anInvalidArgumentException, allowing the exception handler to fall back to the HTML renderer and display the proper 404 error page instead of crashing with HTTP 500.Testing Instructions
Install Joomla 5.4.2.
Open any existing article URL in the frontend.
Append an invalid format parameter, for example:
index.php?option=com_content&view=article&id=111&format=%27Reload the page.
Actual result BEFORE applying this Pull Request
Joomla returns an HTTP 500 error and displays the default error page due to a
TypeErrorcaused byDocument::getType()returningnull.Expected result AFTER applying this Pull Request
Joomla returns a proper 404 error page from the active template without triggering a fatal error, and the request is handled gracefully.
Link to documentations
Please select:
Documentation link for docs.joomla.org:
No documentation changes for docs.joomla.org needed
Pull Request link for manual.joomla.org:
No documentation changes for manual.joomla.org needed