Problem/Motivation

Path comparison (e.g. for block visiblity) doesn't work for aliased internal paths / routes with capital letters for D7 (see block_block_list_alter() function). And D8 + 9 are affected, too.

Both sides of the string comparison must be lowercased, but the (system) path isn't lowercased.

Steps to reproduce

  1. Create an internal path (e.g. for a Views page or with hook_menu()) that contains at least 1 capital letter.
  2. Create an URL alias for that path.
  3. Enter the internal path as visibility page for any block and check that the block visibilty doesn't work as expected.

Proposed resolution

For the comparison of the aliased path everything is fine. But in the 2nd comparison with the internal path there is a missing drupal_strtolower() call for the internal path ($_GET['q']).

For D9 the file /core/modules/system/src/Plugin/Condition/RequestPath.php must be changed from
return $this->pathMatcher->matchPath($path_alias, $pages) || (($path != $path_alias) && $this->pathMatcher->matchPath($path, $pages));
to
return $this->pathMatcher->matchPath($path_alias, $pages) || (($path != $path_alias) && $this->pathMatcher->matchPath(mb_strtolower($path), $pages));

The D7 bugfix is a change in the https://api.drupal.org/api/drupal/modules%21block%21block.module/functio... file from
$page_match = $page_match || drupal_match_path($_GET['q'], $pages);
to
$page_match = $page_match || drupal_match_path(drupal_strtolower($_GET['q']), $pages);

Remaining tasks

  • review existing patch
  • backport for D7

User interface changes

none

API changes

...?

Data model changes

...?

Release notes snippet

...?

Original report by [M_Z]

Short description of the problem: both sides of the string comparison must be lowercased, but the (system) path isn't lowercased…

D7 + D8 are affected by this bug.

-----

API page: https://api.drupal.org/api/drupal/modules%21block%21block.module/functio...

When the path patterns are compared with the current path the block_block_list_alter() function says:

// Compare the lowercase internal and lowercase path alias (if any).

For the comparison of the aliased path everything is fine. But in the 2nd comparison with the internal path there is a missing drupal_strtolower() call for the internal path ($_GET['q']).

So the bugfix would be an easy replacement of the line
$page_match = $page_match || drupal_match_path($_GET['q'], $pages);
with
$page_match = $page_match || drupal_match_path(drupal_strtolower($_GET['q']), $pages);
.

Or is there any mechanism that "auto"-lowercases $_GET['q']? I don't know such a mechanism...

To reproduce the bug create an internal path (e.g. for a Views page or with hook_menu()) that contains at least 1 capital letter. Create an URL alias for that path. Enter the internal path as visibility page for any block and check that the block visibilty doesn't work as expected.

CommentFileSizeAuthor
#71 interdiff_55_71.txt792 bytesRishabh Vishwakarma
#71 2617546-71.patch4.58 KBRishabh Vishwakarma
#70 2617546-67.patch4.58 KBRishabh Vishwakarma
#67 2617546-67.patch4.59 KBRishabh Vishwakarma
#64 interdiff_63-64.txt727 bytesTanuj.
#64 2617546-64.patch2.45 KBTanuj.
#63 2617546-63.patch2.22 KBNikhil_110
#55 interdiff_2617546_53-55.txt1.68 KBankithashetty
#55 2617546-55.patch4.59 KBankithashetty
#53 2617546-53.patch4.67 KBdhirendra.mishra
#53 interdiff_47-53.txt2.07 KBdhirendra.mishra
#50 2617546-after_patch-47.png33.55 KBAbhijith S
#50 2617546-before_patch-47.png32.63 KBAbhijith S
#47 interdiff_39-47.txt1.77 KBravi.shankar
#47 2617546-47.patch4.63 KBravi.shankar
#39 2617546-39.patch4.85 KBhash6
#39 interdiff_33-39.txt3.08 KBhash6
#38 test-only.patch3.82 KBhash6
#33 interdiff-29-33.txt1.58 KBnaresh_bavaskar
#33 2617546-33.patch4.66 KBnaresh_bavaskar
#29 interdiff-21-29.txt4.6 KBHardik_Patel_12
#29 2617546-29.patch4.76 KBHardik_Patel_12
#22 2617546-21.patch785 bytesprabha1997
#22 interdiff_18-21.txt990 bytesprabha1997
#18 block-aliased_internal_paths_with_capital_letters-2617546-18.patch881 bytesHardik_Patel_12
#8 block-aliased_internal_paths_with_capital_letters-2617546-8-TESTS-ONLY.patch3.25 KBDavid_Rothstein
#8 block-aliased_internal_paths_with_capital_letters-2617546-8.patch3.95 KBDavid_Rothstein
#2 block-aliased_internal_paths_with_capital_letters-2617546-2.patch757 bytesM_Z

Issue fork drupal-2617546

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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

M_Z created an issue. See original summary.

M_Z’s picture

I tried to create a patch and set the status to "Needs review".

Maybe someone could create a test based on my "reproduce the bug" description above.

M_Z’s picture

How can I find somebody who reviews my submitted patch?

M_Z’s picture

Issue summary: View changes
brianV’s picture

Status: Needs review » Reviewed & tested by the community

This patch makes the behaviour of the function match the documented behaviour. RTBC.

M_Z’s picture

@Brian: Thank you for reviewing the patch.

M_Z’s picture

What could be done to get the patch committed?

David_Rothstein’s picture

Nice patch, but I think this is really worth writing a test for. Here's a start.

Also, has anyone checked whether this bug affects Drupal 8?

Status: Needs review » Needs work
David_Rothstein’s picture

Status: Needs work » Needs review

M_Z’s picture

@David:
Thank you for writing the test. Your code looks promising since it implements my "reproduce instructions" and your second run (without my patched code) failed testing as expected.

I would recommend to change the status to RTBC.

"Also, has anyone checked whether this bug affects Drupal 8?"

I asked me this question, too.

After some (endless ;-) search I ended here:
https://api.drupal.org/api/drupal/core%21modules%21system%21src%21Plugin...

I also tested that the wrong behaviour exists in Drupal 8 (via my "reproduce instructions").

I will try to create and test a D8 patch as well in the next days.

M_Z’s picture

Title: block_block_list_alter() doesn't work for aliased internal paths with capital letters » Path comparison (e.g. for block visiblity) doesn't work for aliased internal paths with capital letters (block_block_list_alter() in D7)
Version: 7.x-dev » 8.9.x-dev
Issue summary: View changes

The D7 patch is working.

But I changed the issue version to D8 because the core bug exists there, too.

In https://api.drupal.org/api/drupal/core%21modules%21system%21src%21Plugin...

  return $this->pathMatcher
    ->matchPath($path_alias, $pages) || $path != $path_alias && $this->pathMatcher
    ->matchPath($path, $pages);

must be changed to

   return $this->pathMatcher
    ->matchPath($path_alias, $pages) || $path != $path_alias && $this->pathMatcher
    ->matchPath(mb_strtolower($path), $pages);

but I am not experienced in creating the corresponding test. Can anybody help with a test and the patch?

M_Z’s picture

Issue tags: +Needs backport to D7
M_Z’s picture

Status: Needs review » Needs work
Hardik_Patel_12’s picture

Assigned: Unassigned » Hardik_Patel_12
Hardik_Patel_12’s picture

Hardik_Patel_12’s picture

Assigned: Hardik_Patel_12 » Unassigned
M_Z’s picture

Status: Needs review » Needs work

@Hardik_Patel_12: Thank you for your work, but I think it isn't a good idea to lowercase the path before the $path_alias = mb_strtolower($this->aliasManager->getAliasByPath($path)); line (to not break anything for the existing logic).

(And by the way: your first inserted line is useless without a $path = at the beginning.)

My solution from https://www.drupal.org/project/drupal/issues/2617546#comment-13412549 is safe and shouldn't have any side effects:

return $this->pathMatcher
    ->matchPath($path_alias, $pages) || $path != $path_alias && $this->pathMatcher
    ->matchPath(mb_strtolower($path), $pages);

To create this patch would be easy for me, but my request for support was for a test procedure (see the test module for D7 in #2617546-8: Path comparison (e.g. for block visiblity) doesn't work for aliased internal paths with capital letters (block_block_list_alter() in D7)).

If somebody could help with such a D8 test module, his help would be appreciated.

prabha1997’s picture

Assigned: Unassigned » prabha1997

I am working on this issue

prabha1997’s picture

Assigned: prabha1997 » Unassigned
Status: Needs work » Needs review
FileSize
990 bytes
785 bytes
M_Z’s picture

Status: Needs review » Reviewed & tested by the community

@prabha1997: thank you for your patch which contains my proposed solution - so I will set status to RTBC, but a test for D8 is still missing...

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

As @M_Z points out we need an automated test.

I also wonder if we should make \Drupal\Core\Path\PathMatcher::matchPath() do a case insensitive match ie change
$this->regexes[$patterns] = '/^(' . preg_replace($to_replace, $replacements, $patterns_quoted) . ')$/';
to
$this->regexes[$patterns] = '/^(' . preg_replace($to_replace, $replacements, $patterns_quoted) . ')$/i';

and thereby

+++ b/core/modules/system/src/Plugin/Condition/RequestPath.php
@@ -157,7 +157,7 @@ public function evaluate() {
     $path_alias = mb_strtolower($this->aliasManager->getAliasByPath($path));

Remove the mb_strtolower() when you create the $path_alias

I think this is very much inline with #2075889: Make Drupal handle incoming paths in a case-insensitive fashion for routing

alexpott’s picture

Fixing it in \Drupal\Core\Path\PathMatcher::matchPath() would help contrib modules (and custom code) - for example see \Drupal\redirect_404\EventSubscriber\Redirect404Subscriber::onKernelException...

        if ($this->pathMatcher->matchPath(mb_strtolower($path_to_match), $pages)) {
          return;
        }
M_Z’s picture

@alexpott: Thank you for your feedback.

I understand your suggestion, but it could break things (because URLs are case-sensitive by "definition" - e.g. http://www.w3.org/TR/WD-html40-970708/htmlweb.html ). And in Drupal it is easy to create case-sensitve (system) paths, too. Think of two Views pages with one page gets the path '/my-views-page' and the other page has the path '/My-Views-Page'. Both pages are available with their paths and you should be able to set block visibility (or something else) for both paths individually by using its (case-sensitive) paths.
(And even Wikipedia is using case-sensitive paths - e.g. https://webmasters.stackexchange.com/questions/90339/why-are-urls-case-s... )

But I also read #2123543: Add string context and location filters to the translate interface and I decided to make a fresh test with current D8 version via SimplyTestMe and here are my results:

- I create a new View with 2 page displays
- the 1st page has the path /example-path
- the 2nd page has the path /Example-Path
- so far so good: both pages are available with their (system) paths
- then I added URL aliases for both paths (and the URL aliases are totally different - e.g. /my-example-path-1 for the 1st page and /my-example-path-2 for the 2nd page)
- by the way: the URL alias for the 1st page isn't used in the Views UI backend and the URL alias for the 2nd page is used for both "View page" links in the Views UI backend and the Views overview list on /admin/structure/views --> I created another issue for this bug #3124764: Wrong path alias (for Views pages) with case-sensitve (system) paths
- but from the URL aliases backend both aliased paths can be called
- add a block that is visible for /example-path --> this works as expected and the block is visible on /my-example-path-1
- add a different block that is visible for /Example-Path --> this doesn't work and the block that should be shown on /my-example-path-2 is only visible on /my-example-path-1

My initial suggestion in this issue was to fix an obvious and reproducable error and only the automated test is missing up to now...

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

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now 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.

Hardik_Patel_12’s picture

Assigned: Unassigned » Hardik_Patel_12

working on it.

Hardik_Patel_12’s picture

FileSize
4.76 KB
4.6 KB

Adding test case. Kindly review a new patch.

Hardik_Patel_12’s picture

Assigned: Hardik_Patel_12 » Unassigned
Status: Needs work » Needs review
Lendude’s picture

Status: Needs review » Needs work

@Hardik_Patel_12 can you please add a test only patch (one with just your test in it and not the fix) so we can see that this is accurately reproducing the bug

  1. +++ b/core/modules/block/tests/modules/block_test/src/Controller/TestMultipleFormController.php
    @@ -6,10 +6,13 @@
    +  /**
    +   *
    +   */
       public function testMultipleForms() {
    

    this is an unrelated change, no need to do that in this patch

  2. +++ b/core/modules/block/tests/modules/block_test/src/Controller/TestMultipleFormController.php
    @@ -37,4 +40,14 @@ public function testMultipleForms() {
    +  /**
    +   *
    +   */
    +  public function testblock() {
    

    this seems to be missing some text and maybe a more descriptive name?

  3. +++ b/core/modules/block/tests/src/Functional/BlockTestWithCapitalLetters.php
    @@ -0,0 +1,59 @@
    +    $this->drupalGet('admin/structure/block/add/' . $block_name . '/' . $default_theme);
    +    $this->drupalPostForm(NULL, $edit, t('Save block'));
    

    no need to Get first, you can just use the path as the first argument in drupalPostForm instead of NULL

naresh_bavaskar’s picture

Assigned: Unassigned » naresh_bavaskar
naresh_bavaskar’s picture

Assigned: naresh_bavaskar » Unassigned
Status: Needs work » Needs review
FileSize
4.66 KB
1.58 KB

@Lendude Addressed suggested changes,
Please review

Hardik_Patel_12’s picture

Issue tags: +Bug Smash Initiative
Lendude’s picture

Status: Needs review » Needs work

Some more feedback.

  1. Can we get a test-only patch please (see #31)
  2. +++ b/core/modules/block/tests/modules/block_test/block_test.routing.yml
    @@ -5,3 +5,10 @@ block_test.test_multipleforms:
    +    _controller: '\Drupal\block_test\Controller\TestMultipleFormController::testblock'
    
    +++ b/core/modules/block/tests/modules/block_test/src/Controller/TestMultipleFormController.php
    @@ -37,4 +37,14 @@ public function testMultipleForms() {
    +   * Testing page block.
    ...
    +  public function testblock() {
    

    Can we come up with something a little bit more descriptive then 'testblock'

  3. +++ b/core/modules/block/tests/modules/block_test/src/Controller/TestMultipleFormController.php
    @@ -6,7 +6,7 @@
    - * Controller for block_test module
    + * Controller for block_test module.
    

    unrelated change

  4. +++ b/core/modules/block/tests/src/Functional/BlockTestWithCapitalLetters.php
    @@ -0,0 +1,59 @@
    +    // Check on front page block is not placed.
    ...
    +    // Check on 'BlockTestPageWithCapitalLetters' page block is placed.
    ...
    +    // CHeck on alias page block is placed.
    

    These comments need to be full English sentences, these are a bit off.

Hardik_Patel_12’s picture

Issue tags: -Bug Smash Initiative
hash6’s picture

Assigned: Unassigned » hash6
hash6’s picture

added the test only patch @lendude, will work the wordings. So #1 is fixed, working on others.

hash6’s picture

updated the wordings as mentioned in the #2 , #3 and #4 @Lendude

Hardik_Patel_12’s picture

Status: Needs work » Needs review
hash6’s picture

Assigned: hash6 » Unassigned

The last submitted patch, 38: test-only.patch, failed testing. View results

M_Z’s picture

@hash6: I reviewed your patch and I think that now all points of @Lendude are finished, so it looks like RTBC

but maybe someone else could check your last patch (because I am not that familiar with the test coding), but the "failed" test-only.patch and the "passed" #39 patch is a good indication that all of you did a good job

Thanks @all and I am happy to see some "action" in this issue

Hardik_Patel_12’s picture

Status: Needs review » Reviewed & tested by the community

Patch at 39 looks good to me and it has covered all points suggested at #35.

The last submitted patch, 38: test-only.patch, failed testing. View results

larowlan’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Bug Smash Initiative

Thanks for working on this 💪

  1. +++ b/core/modules/block/tests/modules/block_test/src/Controller/TestMultipleFormController.php
    @@ -6,7 +6,7 @@
    - * Controller for block_test module
    + * Page with Capital Lettered Url to test block's page visibility.
    

    This change is out of scope here

  2. +++ b/core/modules/block/tests/modules/block_test/src/Controller/TestMultipleFormController.php
    @@ -37,4 +37,14 @@ public function testMultipleForms() {
    +      '#markup' => $this->t('Test Block for Page with Capital Letters .'),
    

    this isn't a block, its a controller, not sure about the use of 'Block' in the markup, but its minor

  3. +++ b/core/modules/block/tests/src/Functional/BlockTestWithCapitalLetters.php
    @@ -0,0 +1,59 @@
    +
    

    nit: this extra line isn't needed

ravi.shankar’s picture

Status: Needs work » Needs review
FileSize
4.63 KB
1.77 KB

Here I have addressed #46.1 and #46.3 points of comment #46 and line exceeding more than 80 characters issue.

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

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

tanubansal’s picture

Tested #47 on 9.1 -
1. #46.1 and #46.3 points of comment #46 are resolved
2. Line exceeding more than 80 characters issue is also resolved

Abhijith S’s picture

Applied patch #47 on 9.2.x and it works fine. Including screenshots below.

Before (Block not displaying with given path containing capital letter) :
before

After( Block is showing now):
after

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

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update

Came to do a review but the issue summary does not state the proposed resolution, tagging for an IS update. I think this could use a better title too.

@Abhijith S, it helps the reviewer to have the screenshots in the Issue Summary.

Then I looked at the code.

  1. +++ b/core/modules/block/tests/modules/block_test/src/Controller/TestMultipleFormController.php
    @@ -37,4 +37,14 @@ public function testMultipleForms() {
    +   * Test block visibility on a page with Capital Letters in the URL.
    

    s/Capital Letters/capital letters/

  2. +++ b/core/modules/block/tests/modules/block_test/src/Controller/TestMultipleFormController.php
    @@ -37,4 +37,14 @@ public function testMultipleForms() {
    +      '#markup' => $this->t('Test Block for Page with Capital Letters .'),
    

    s/Letters ./Letters./

  3. +++ b/core/modules/block/tests/src/Functional/BlockTestWithCapitalLetters.php
    @@ -0,0 +1,59 @@
    + * Tests block with capital letter path functionality.
    

    This could be clearer. Can't think of alternatives right now.

  4. +++ b/core/modules/block/tests/src/Functional/BlockTestWithCapitalLetters.php
    @@ -0,0 +1,59 @@
    +    $this->assertNoText($title, 'Block was not displayed on the front page.');
    

    Remove the message in this assertion and the other assertions.

  5. +++ b/core/modules/block/tests/src/Functional/BlockTestWithCapitalLetters.php
    @@ -0,0 +1,59 @@
    +    // Test the page with url 'BlockTestPageWithCapitalLetters' where block
    +    // should be visible.
    

    I think 'Test that the block is visible on /BlockTestPageWithCapitalLetters' is much easier to understand.

  6. +++ b/core/modules/block/tests/src/Functional/BlockTestWithCapitalLetters.php
    @@ -0,0 +1,59 @@
    +    // Test the page with it's alias where block should be visible.
    

    I think 'Use the alias and test that the block is visible on /BlockTestPageWithCapitalLetters' is much easier to understand.

dhirendra.mishra’s picture

Status: Needs work » Needs review
FileSize
2.07 KB
4.67 KB

Here uploading my patch.

pls review it

Status: Needs review » Needs work

The last submitted patch, 53: 2617546-53.patch, failed testing. View results

ankithashetty’s picture

Status: Needs work » Needs review
FileSize
4.59 KB
1.68 KB

Fixed test failures in #53, thanks!

M_Z’s picture

@all: Thank you for your work on this issue.

In some days it will be the 6th anniversary of my issue creation that included the bugfix / solution right from the beginning.

I understand the importance of automated testing, but an easy reproducible bug should be fixed a little bit faster in my opinion...

I keep the fingers crossed that this issue is close to be closed ;-)

quietone’s picture

Status: Needs review » Needs work
Issue tags: +Novice

This still needs an issue summary update, see Write an issue summary for an existing issue for guidance. Particularly, the proposed resolution - that allows the reviewer to confirm that the patch is doing what it is supposed to be doing.

Updating the IS is a suitable novice issue, adding tag.

M_Z’s picture

Issue summary: View changes
M_Z’s picture

@quietone: I made a start with the IS update.

Anybody can feel free to improve it - especially the parts with "...?"

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

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.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.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now 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.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now 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.

Nikhil_110’s picture

Attached patch against Drupal 10.1.x

Tanuj.’s picture

Fixed CCF on #63 and rerolled for Drupal 10.1.x

Tanuj.’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work

Removing credit from both #63 and #64 as #63 didn't check the patch before uploading and removed the fix and some of the tests. #64 carried it forward.

Also patch #55 still applies to D10.1 so a reroll was not needed.

#55 tests will have to be updated for D10.1

Rishabh Vishwakarma’s picture

Status: Needs work » Needs review
FileSize
4.59 KB

Test only patch

Status: Needs review » Needs work

The last submitted patch, 67: 2617546-67.patch, failed testing. View results

Rishabh Vishwakarma’s picture

Rishabh Vishwakarma’s picture

Status: Needs work » Needs review
FileSize
4.58 KB

Test only patch

Rishabh Vishwakarma’s picture

FileSize
4.58 KB
792 bytes

Updated the test as mentioned in #66

smustgrave’s picture

Status: Needs review » Needs work

We shouldn’t use olivero in a test unless we have to.

Version: 10.1.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, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Hardik_Patel_12’s picture

An issue summary update is still needed.

smustgrave’s picture

FYI this issue was tagged for novice for new users. You have 26 pages of posts so definitely not novice. Please try to avoid novice issues in the future

Thanks!

M_Z’s picture

I want to thank everybody who is still working on that issue that I reported more than 8 years ago (for Drupal 7). My initial bug report contained the solution to fix this bug. I also posted a solution to fix this bug for Drupal 8+ more than 4 years ago. I don't think that tests are useless, but this core bug could have been fixed years ago.

There aren't tests for all PHP lines in the core code. I'm not quite sure if the test for this issue is that essential and relevant. Other "if" statements in core code haven't a corresponding test coverage, too.

I would suggest to fix this bug in the near future and maybe add a follow-up issue for test coverage. But maybe all the hard-working helpers in this issue are near the finish line to get this solved inclusive test coverage...