User tests: Successful: Unsuccessful:
Pull Request for Issue #46730 .
Changed the default value of Document::$_type from null to an empty string.
When an invalid or cleaned format parameter results in an empty output format, the document type remains unset (null). This causes a TypeError later 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 an InvalidArgumentException, allowing the exception handler to fall back to the HTML renderer and display the proper 404 error page instead of crashing with HTTP 500.
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=%27
Reload the page.
Joomla returns an HTTP 500 error and displays the default error page due to a TypeError caused by Document::getType() returning null.
Joomla returns a proper 404 error page from the active template without triggering a fatal error, and the request is handled gracefully.
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
| Status | New | ⇒ | Pending |
| Category | ⇒ | Libraries |
I have tested this item ✅ successfully on e355131
This PR fixes a fatal error ensuring that the Document Factory fails gracefully when an invalid or empty format is requested.
Changes:
$type is empty.This resolves the crash when visiting URLs with empty format parameters (e.g., ?format=).
@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
This PR correctly fixes the issue where Document::$type could remain null when an invalid format parameter is passed.
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.
I have tested this item ✅ successfully on e355131
Test Results:
✓ Valid format (html) - Works correctly
✓ Invalid format (invalid123) - No crash, falls back to RawDocument
✓ Special characters (!@#$%) - No crash, characters sanitized
✓ Empty format - No crash, handled gracefully
This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/46790.