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
- 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.
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.
Comment | File | Size | Author |
---|---|---|---|
#71 | interdiff_55_71.txt | 792 bytes | Rishabh Vishwakarma |
#71 | 2617546-71.patch | 4.58 KB | Rishabh Vishwakarma |
| |||
#70 | 2617546-67.patch | 4.58 KB | Rishabh Vishwakarma |
| |||
#55 | interdiff_2617546_53-55.txt | 1.68 KB | ankithashetty |
#55 | 2617546-55.patch | 4.59 KB | ankithashetty |
Issue fork drupal-2617546
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
M_Z CreditAttribution: M_Z commentedI 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.
Comment #3
M_Z CreditAttribution: M_Z commentedHow can I find somebody who reviews my submitted patch?
Comment #4
M_Z CreditAttribution: M_Z commentedComment #5
brianV CreditAttribution: brianV as a volunteer commentedThis patch makes the behaviour of the function match the documented behaviour. RTBC.
Comment #6
M_Z CreditAttribution: M_Z commented@Brian: Thank you for reviewing the patch.
Comment #7
M_Z CreditAttribution: M_Z commentedWhat could be done to get the patch committed?
Comment #8
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedNice 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?
Comment #11
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedComment #13
M_Z CreditAttribution: M_Z commented@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.
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.
Comment #14
M_Z CreditAttribution: M_Z commentedThe 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...
must be changed to
but I am not experienced in creating the corresponding test. Can anybody help with a test and the patch?
Comment #15
M_Z CreditAttribution: M_Z commentedComment #16
M_Z CreditAttribution: M_Z commentedComment #17
Hardik_Patel_12 CreditAttribution: Hardik_Patel_12 at QED42 commentedComment #18
Hardik_Patel_12 CreditAttribution: Hardik_Patel_12 at QED42 commentedHello @M_Z,
I have verified that issue is still there in D8, so kindly review a new patch for D8
Comment #19
Hardik_Patel_12 CreditAttribution: Hardik_Patel_12 at QED42 commentedComment #20
M_Z CreditAttribution: M_Z commented@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:
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.
Comment #21
prabha1997 CreditAttribution: prabha1997 at Valuebound for Valuebound commentedI am working on this issue
Comment #22
prabha1997 CreditAttribution: prabha1997 at Valuebound for Valuebound commentedComment #23
M_Z CreditAttribution: M_Z commented@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...
Comment #24
alexpottAs @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
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
Comment #25
alexpottFixing it in
\Drupal\Core\Path\PathMatcher::matchPath()
would help contrib modules (and custom code) - for example see \Drupal\redirect_404\EventSubscriber\Redirect404Subscriber::onKernelException...Comment #26
M_Z CreditAttribution: M_Z commented@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...
Comment #28
Hardik_Patel_12 CreditAttribution: Hardik_Patel_12 at QED42 commentedworking on it.
Comment #29
Hardik_Patel_12 CreditAttribution: Hardik_Patel_12 at QED42 commentedAdding test case. Kindly review a new patch.
Comment #30
Hardik_Patel_12 CreditAttribution: Hardik_Patel_12 at QED42 commentedComment #31
Lendude@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
this is an unrelated change, no need to do that in this patch
this seems to be missing some text and maybe a more descriptive name?
no need to Get first, you can just use the path as the first argument in drupalPostForm instead of NULL
Comment #32
naresh_bavaskarComment #33
naresh_bavaskar@Lendude Addressed suggested changes,
Please review
Comment #34
Hardik_Patel_12 CreditAttribution: Hardik_Patel_12 at QED42 commentedComment #35
LendudeSome more feedback.
Can we come up with something a little bit more descriptive then 'testblock'
unrelated change
These comments need to be full English sentences, these are a bit off.
Comment #36
Hardik_Patel_12 CreditAttribution: Hardik_Patel_12 at QED42 commentedComment #37
hash6 CreditAttribution: hash6 at QED42 for Drupal India Association commentedComment #38
hash6 CreditAttribution: hash6 at QED42 for Drupal India Association commentedadded the test only patch @lendude, will work the wordings. So #1 is fixed, working on others.
Comment #39
hash6 CreditAttribution: hash6 at QED42 for Drupal India Association commentedupdated the wordings as mentioned in the #2 , #3 and #4 @Lendude
Comment #40
Hardik_Patel_12 CreditAttribution: Hardik_Patel_12 at QED42 commentedComment #41
hash6 CreditAttribution: hash6 at QED42 for Drupal India Association commentedComment #43
M_Z CreditAttribution: M_Z commented@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
Comment #44
Hardik_Patel_12 CreditAttribution: Hardik_Patel_12 at QED42 for Drupal India Association commentedPatch at 39 looks good to me and it has covered all points suggested at #35.
Comment #46
larowlanThanks for working on this 💪
This change is out of scope here
this isn't a block, its a controller, not sure about the use of 'Block' in the markup, but its minor
nit: this extra line isn't needed
Comment #47
ravi.shankar CreditAttribution: ravi.shankar at OpenSense Labs commentedHere I have addressed #46.1 and #46.3 points of comment #46 and line exceeding more than 80 characters issue.
Comment #49
tanubansal CreditAttribution: tanubansal at Salsa Digital commentedTested #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
Comment #50
Abhijith S CreditAttribution: Abhijith S as a volunteer and at Zyxware Technologies commentedApplied patch #47 on 9.2.x and it works fine. Including screenshots below.
Before (Block not displaying with given path containing capital letter) :
After( Block is showing now):
Comment #52
quietone CreditAttribution: quietone as a volunteer commentedCame 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.
s/Capital Letters/capital letters/
s/Letters ./Letters./
This could be clearer. Can't think of alternatives right now.
Remove the message in this assertion and the other assertions.
I think 'Test that the block is visible on /BlockTestPageWithCapitalLetters' is much easier to understand.
I think 'Use the alias and test that the block is visible on /BlockTestPageWithCapitalLetters' is much easier to understand.
Comment #53
dhirendra.mishra CreditAttribution: dhirendra.mishra at Valuebound for Valuebound commentedHere uploading my patch.
pls review it
Comment #55
ankithashettyFixed test failures in #53, thanks!
Comment #56
M_Z CreditAttribution: M_Z commented@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 ;-)
Comment #57
quietone CreditAttribution: quietone as a volunteer commentedThis 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.
Comment #58
M_Z CreditAttribution: M_Z commentedComment #59
M_Z CreditAttribution: M_Z commented@quietone: I made a start with the IS update.
Anybody can feel free to improve it - especially the parts with "...?"
Comment #63
Nikhil_110 CreditAttribution: Nikhil_110 at Srijan | A Material+ Company commentedAttached patch against Drupal 10.1.x
Comment #64
Tanuj. CreditAttribution: Tanuj. as a volunteer and at Srijan | A Material+ Company for Drupal India Association commentedFixed CCF on #63 and rerolled for Drupal 10.1.x
Comment #65
Tanuj. CreditAttribution: Tanuj. as a volunteer and at Srijan | A Material+ Company for Drupal India Association commentedComment #66
smustgrave CreditAttribution: smustgrave at Mobomo commentedRemoving 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
Comment #67
Rishabh Vishwakarma CreditAttribution: Rishabh Vishwakarma at OpenSense Labs for DrupalFit commentedTest only patch
Comment #69
Rishabh Vishwakarma CreditAttribution: Rishabh Vishwakarma at OpenSense Labs for DrupalFit commentedComment #70
Rishabh Vishwakarma CreditAttribution: Rishabh Vishwakarma at OpenSense Labs for DrupalFit commentedTest only patch
Comment #71
Rishabh Vishwakarma CreditAttribution: Rishabh Vishwakarma at OpenSense Labs for DrupalFit commentedUpdated the test as mentioned in #66
Comment #72
smustgrave CreditAttribution: smustgrave at Mobomo commentedWe shouldn’t use olivero in a test unless we have to.
Comment #75
Hardik_Patel_12 CreditAttribution: Hardik_Patel_12 at Axelerant for Drupal India Association commentedAn issue summary update is still needed.
Comment #76
smustgrave CreditAttribution: smustgrave at Mobomo commentedFYI 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!
Comment #77
M_Z CreditAttribution: M_Z commentedI 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...