In testing, this module always redirected users to their user information page if they where trying to go to the homepage, for example 'example.com'. In testing the issue, I have come across the issue in AnonymousLoginSubscriber.php.
- On lines 177-180 the current path is stored. In case for the front page of the site, it comes back as
/. - On line 205, the front page setting is fetched. In my case it comes back as something like
/node/4.
On line 206, the module tries to check to see if the current path matches the front page setting, but it never does. This is because the URL 'example.com' always has a path of /, and the set front pate will always have /node/4. This will cause <front> to never be set, and / will be the set as $current['path'].
The second part of the issue comes on line 214 where the path is sent to the pathSlashCut function that strips the leading and trailing slashes form the path. Since the path only has /, the slash is stripped, leaving an empty path. In my instances of Drupal, when an empty path is requested, it forces the system to redirect the user to their information page. The user doesn't end up at the front page as expected.
One possible solution that I thought of is to have the pathSlashCut function look to see if the path only contains a /, and if it does, then don't strip the slashes:
if($path_string !== '/') {
// Remove the leading slash.
if (substr($path_string, 0, 1) == '/') {
$path_string = substr($path_string, 1);
}
// Remove the trailer slash.
if (substr($path_string, -1) == '/') {
$path_string = substr($path_string, 0, strlen($path_string) - 1);
}
}
The other solution would be to make the comparison on line 206 looking for the front page smarter by having it understand that '/' means the front page, and thus setting the path as <front>:
$current['path'] = ($current['path'] != $front_page && $current['path'] !== '/') ? $current['path'] : '<front>';
In my testing, both work well. I'm thinking that the second solution would be the more elegant solution. I'll have a patch file ready shortly with the change.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | anonymous_login-front_page_redirect-3054482-4.patch | 2.36 KB | jazzfiction |
| #3 | anonymous_login-front_page_redirect-3054482-3.patch | 756 bytes | jazzfiction |
Issue fork anonymous_login-3054482
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
jazzfiction commentedUpdated my original post to reflect the change in line numbers with the current dev version as of this post.
Comment #3
jazzfiction commentedUploading the patch file.
Comment #4
jazzfiction commentedIn further testing, I found that the first part of my suggestion above in modifying the
pathSlashCutfunction is also needed. I have modified it to check for the single slash, and if it is found, then url encode it. In testing, this version of the patch works with my Drupal sites.Comment #5
jazzfiction commentedComment #6
ergonlogicI can confirm this bug, and that it still exists on the current release (8.x-2.1).
Also, the patch in #4 fixes it.
Comment #9
japerryThe fact that this doesn't include a test, nor does it make existing tests fail, while being a fundamental change of the modules functionality (defaulting redirect from false to true) -- is probably a big enough gap to mark needs work, until a test is added that confirms the new functionality. (or at least confirms the current functionality is broken)
Comment #12
anton4uk commentedIn the current 8.x-2.x, the original bug is already fixed by https://www.drupal.org/project/anonymous_login/issues/3346519. / now redirects to /user/login?destination=/.
A related bug remains: the keyword never matches. MR !12 (based on old code) removes the include check ($redirect = TRUE), so every page not in the exclude list redirects.
MR !25 handles directly and adds a functional test using the PathMatcher. Two of its tests fail on the current 8.x-2.x, three fail with MR !12, and all pass with the fix.
Thanks @jazzfiction, @ergonlogic, and @japerry.
Comment #14
anton4uk commentedComment #17
japerryComment #18
japerryThe fix released in 8.x-2.3 has a regression for sites installed in a subdirectory.
Until 8.x-2.2 the base path was added to the path before it was matched, so those sites had to use patterns such as subdirectory/node/*. Since 8.x-2.3 paths are matched without the base path, so those patterns match nothing: included pages become public and excluded pages are redirected.
MR !33 does the following: