Skip to content

Fix #46730: Prevent crash when format parameter is invalid#46790

Open
VaishnaviSidral wants to merge 2 commits intojoomla:5.4-devfrom
VaishnaviSidral:Issue#46730
Open

Fix #46730: Prevent crash when format parameter is invalid#46790
VaishnaviSidral wants to merge 2 commits intojoomla:5.4-devfrom
VaishnaviSidral:Issue#46730

Conversation

@VaishnaviSidral
Copy link

@VaishnaviSidral VaishnaviSidral commented Jan 31, 2026

Pull Request for Issue #46730 .

Summary of Changes

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.

Testing Instructions

  1. Install Joomla 5.4.2.

  2. Open any existing article URL in the frontend.

  3. Append an invalid format parameter, for example:

    index.php?option=com_content&view=article&id=111&format=%27

  4. Reload the page.

Actual result BEFORE applying this Pull Request

Joomla returns an HTTP 500 error and displays the default error page due to a TypeError caused by Document::getType() returning null.

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

@ompatwa000-svg
Copy link

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.

@465645
Copy link

465645 commented Jan 31, 2026

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:

  • Modified libraries/src/Document/Factory.php to check if the sanitized $type is empty.
  • Defaults to 'html' if the type is invalid/empty, preventing the instantiation of the abstract Document class.

This resolves the crash when visiting URLs with empty format parameters (e.g., ?format=).


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/46790.

@brianteeman
Copy link
Contributor

@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

image

@bembelimen bembelimen added the Updates Requested Indicates that this pull request needs an update from the author and should not be tested. label Jan 31, 2026
@joomdonation
Copy link
Contributor

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)

@vidya1111-gangji
Copy link

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.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/46790.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR-5.4-dev Updates Requested Indicates that this pull request needs an update from the author and should not be tested.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants