If you try to clear the AliasManager cache for the root path / then PHP will raise a warning: array_key_exists(): The first argument should be either a string or an integer AliasWhitelist.php:95

The reason for this is that strtok('/', '/') will return FALSE.

Issue fork drupal-2939397

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

kasperg created an issue. See original summary.

kasperg’s picture

Here is a patch that tries to address this issue.

The patch treats / as a special case which seems to be the same approach taken elsewhere within the class.

kasperg’s picture

Status: Active » Needs review

Status: Needs review » Needs work
kasperg’s picture

Status: Needs work » Needs review
StatusFileSize
new1.88 KB

Another attempt which should fix the test case.

Status: Needs review » Needs work
kasperg’s picture

Status: Needs work » Needs review
dawehner’s picture

+++ b/core/lib/Drupal/Core/Path/AliasManager.php
@@ -281,7 +281,7 @@ protected function pathAliasWhitelistRebuild($path = NULL) {
     // When paths are inserted, only rebuild the whitelist if the path has a top
     // level component which is not already in the whitelist.
     if (!empty($path)) {
-      if ($this->whitelist->get(strtok($path, '/'))) {
+      if ($path !== '/' && $this->whitelist->get(strtok($path, '/'))) {
         return;

It would be nice to document why we need to do this extra check for

$path !==
 '/'
kasperg’s picture

#8: I also thought about that.

From one perspective I think it is already explained within the current comment:

only rebuild the whitelist if the path has a top-level component which is not already in the whitelist

Obviously, the path / does not have a top-level component and if you know how strtok() works, you will also know that it is this situation may return a boolean. Non-string arguments will make AliasWhitelist produce a warning. Also the same approach is used elsewhere in the AliasManager.

On the other hand, it was my first encounter with strtok() and the current issue points to the fact that it is not trivial. You could use other forms of string manipulation like substr() + strpos() or regular expressions but that seems cumbersome as well.

I tried to rework the two places the function is used in this patch.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jwilson3’s picture

Version: 8.6.x-dev » 8.8.x-dev
StatusFileSize
new2.67 KB

Re-roll for Drupal 8.8+ where AliasManagerTest.php was moved from a sub-system of core into the new path_alias core module.

I agree with @kasperg's reasoning for why adding additional documentation to single out $path !== '/' is not really necessary, and I think the new code with existing comment will be well understood.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

meladawy’s picture

This should be compatible with 9.2.x

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
meladawy’s picture

9.3.x compatible patch

gauravvvv’s picture

StatusFileSize
new2.32 KB
new646 bytes

Fixed custom command failed, Attached interdiff for same. Please review

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new144 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

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

gauravvvv’s picture

Updating attributions

sahil.goyal made their first commit to this issue’s fork.

Oops! something wrong happened MR showing wrong commits, need to close

sahil.goyal’s picture

StatusFileSize
new2.39 KB
new1.22 KB

Updating the latest MR, facing some issue to fork MR so updating the patch, #17 and #22 does not seem diff so updating interdiff with 17. and made condition so trying to resolve failures.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.