PR-5.3-dev Pending

User tests: Successful: Unsuccessful:

avatar AdarshSantoria
AdarshSantoria
29 Mar 2025

Pull Request for Issue #45227

Summary of Changes

This PR fixes the incorrect behavior of Uri::reset() affecting the route generation in Joomla when called in the administrator context.

After calling Uri::reset(), subsequent calls to Route::link('site', ...) incorrectly prepend /administrator/ to the generated URLs. This happens because Uri::getInstance() rebuilds the root path from the admin context after the reset.

This PR updates the Uri::root() method to strip /administrator from the path when generating site URLs, ensuring consistent URL generation across contexts.

Testing Instructions

Use the following test snippet in an administrator view (HtmlView::display()):

use Joomla\CMS\Router\Route;
use Joomla\CMS\Uri\Uri;

// Link from site context
$link1 = Route::link('site', 'index.php', absolute: true);
echo "Link 1: $link1<br>";

// Reset Uri cache
Uri::reset();

// Link from site context (cached root rebuilt)
$link2 = Route::link('site', 'index.php', absolute: true);
echo "Link 2: $link2<br>";

// Link from site context with query param
$link3 = Route::link('site', 'index.php?b', absolute: true);
echo "Link 3: $link3<br>";

// Link from admin context (should still include /administrator)
$link4 = Route::link('administrator', 'index.php?b', absolute: true);
echo "Link 4: $link4<br>";

Actual result BEFORE applying this Pull Request

Link 1: http://localhost/joomla-cms/index.php
Link 2: http://localhost/joomla-cms/index.php
Link 3: http://localhost/joomla-cms/administrator/index.php?b=
Link 4: http://localhost/joomla-cms/administrator/administrator/index.php?b=

Expected result AFTER applying this Pull Request

Link 1: http://localhost/joomla-cms/index.php
Link 2: http://localhost/joomla-cms/index.php
Link 3: http://localhost/joomla-cms/index.php?b=
Link 4: http://localhost/joomla-cms/administrator/index.php?b=

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

avatar AdarshSantoria AdarshSantoria - open - 29 Mar 2025
avatar AdarshSantoria AdarshSantoria - change - 29 Mar 2025
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 29 Mar 2025
Category Libraries
avatar AdarshSantoria AdarshSantoria - edited - 29 Mar 2025
avatar AdarshSantoria AdarshSantoria - change - 29 Mar 2025
Title
Fix Uri::root() adding /administrator to site URLs after reset
[5.3] Fix Uri::root() adding /administrator to site URLs after reset
avatar brbrbr
brbrbr - comment - 30 Mar 2025

The issue is resolved.

I didn't notice before, but Uri:reset() just breaks everything resource link in the administrator, not in the front-end. With and without this PR.

It's probably a somewhat theoretical problem, since the Uri:reset is not used anywhere except for the front end module manager.

Thanks for the effort. My tests will run correctly with the PR.

avatar fgsw
fgsw - comment - 30 Mar 2025

@brbrbr Can you open https://issues.joomla.org/tracker/joomla-cms/45252 and

Login with your github-account and

  1. click button "Test this"
  2. mark "Tested successfully"
  3. click button "Submit test result".
test-pr-submit

Now the test count as successfull.

avatar brbrbr brbrbr - test_item - 30 Mar 2025 - Tested successfully
avatar brbrbr
brbrbr - comment - 30 Mar 2025

I have tested this item ✅ successfully on d4bacfc


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

avatar Hackwar
Hackwar - comment - 31 Mar 2025

I will still have to look into this issue further, but you can't simply hardcode it like this. People do have changed their admin folder and if we have this issue here, we will most likely also have this in the /api as well.

avatar AdarshSantoria AdarshSantoria - change - 2 Apr 2025
Labels Added: PR-5.3-dev
avatar AdarshSantoria
AdarshSantoria - comment - 2 Apr 2025

I will still have to look into this issue further, but you can't simply hardcode it like this. People do have changed their admin folder and if we have this issue here, we will most likely also have this in the /api as well.

Hi @Hackwar, thanks for the feedback. I’ve just updated the code to remove the hardcoded path. It now uses the same logic as in
installation/src/Application/InstallationApplication.php.
This should work correctly with custom admin folders and /api as well.

avatar brbrbr brbrbr - test_item - 2 Apr 2025 - Tested unsuccessfully
avatar brbrbr
brbrbr - comment - 2 Apr 2025

I have tested this item 🔴 unsuccessfully on 1157728

adminstrtor path on a domain installation: example.com/adminstrator is not removed


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

avatar brbrbr
brbrbr - comment - 2 Apr 2025

I think the problem is somewhere else:

libraries/src/Application/AdministratorApplication.php via:

Uri::root(null, rtrim(\dirname(Uri::base(true)), '/\\'));

sets the static::$root['path'] in libraries/src/Uri/Uri.php, confusingly commented as Get while its a Set

 // Get the scheme
if (isset($path)) {
            static::$root['path'] = $path;
        }

Which is also reset.

that explains why the media links ain't working either after a Uri::reset()

avatar brbrbr
brbrbr - comment - 2 Apr 2025

Still the static::$root['path'] is reset with Uri:reset and not set again by the applications.

So after a Uri::reset() an application dependend set of the path using the 'setter' root(null,path) is needed.

That is not a problem in the context that I found the original problem.

Or static::$root['path'] should not be part of the reset.

Add a Comment

Login with GitHub to post a comment