User tests: Successful: Unsuccessful:
Pull Request for Issue #45227
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.
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>";
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=
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=
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 |
Title |
|
@brbrbr Can you open https://issues.joomla.org/tracker/joomla-cms/45252 and
Login with your github-account and
Now the test count as successfull.
I have tested this item ✅ successfully on d4bacfc
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.
Labels |
Added:
PR-5.3-dev
|
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.
I have tested this item 🔴 unsuccessfully on 1157728
adminstrtor path on a domain installation: example.com/adminstrator is not removed
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()
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.
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.