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.

Command icon 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

jazzfiction created an issue. See original summary.

jazzfiction’s picture

Issue summary: View changes

Updated my original post to reflect the change in line numbers with the current dev version as of this post.

jazzfiction’s picture

Uploading the patch file.

jazzfiction’s picture

In further testing, I found that the first part of my suggestion above in modifying the pathSlashCut function 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.

jazzfiction’s picture

Status: Active » Needs review
ergonlogic’s picture

Version: 8.x-1.x-dev » 8.x-2.x-dev
Status: Needs review » Reviewed & tested by the community

I can confirm this bug, and that it still exists on the current release (8.x-2.1).

Also, the patch in #4 fixes it.

japerry made their first commit to this issue’s fork.

japerry’s picture

Status: Reviewed & tested by the community » Needs work

The 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)

anton4uk made their first commit to this issue’s fork.

anton4uk’s picture

Status: Needs work » Needs review

In 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.

  • anton4uk committed 0fd94040 on 8.x-2.x
    Issue #3054482: Fix the <front> keyword in redirect paths
    
anton4uk’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

japerry’s picture

Status: Fixed » Needs review
japerry’s picture

Priority: Normal » Critical

The 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:

  • AnonymousLoginSubscriber::redirect() matches the path, the alias and the path as requested with the base path in front as well as without it. Patterns written for 8.x-2.2 and patterns without the base path both work.
  • Added unit test cases for includes and excludes with the base path, with and without a language prefix. They fail on 8.x-2.x.