Closed (fixed)
Project:
Drupal core
Version:
10.1.x-dev
Component:
block.module
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
16 Jan 2017 at 17:42 UTC
Updated:
24 Jul 2023 at 17:15 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
jasonawantI added validateConfigurationForm method to validate the paths. I'd appreciate any feedback regarding the logic, and if we need test coverage. I haven't written any tests, but I'd like to get the experience. Jason
Comment #3
krishkasc commentedI have tested the patch and its working fine in drupal 8.2.
Comment #4
krishkasc commentedI have tested the patch with drupal 8.2 and properly validating the forward slash on the url key.
Comment #5
tim.plunkettNice work!
This needs automated tests before it can go in
Comment #6
jasonawantHi,
I'd like to work on this test coverage, but would like if someone could confirm I'm heading in the right direct. This will be my first test to write.
I think I need to add a new test in BlockUiTest, which would use drupalPostForm to try to save either of the setUp Tools or Powered by Drupal blocks with the additional page visibility value to trigger the validation error, and then use assertText to see if the error message text is on the page. Does that sound about right?
Well, maybe not, because the new validation occurs within the RequestPath condition, which could be used as a plugin elsewhere.
Instead of expanding the BlockUiTest tests, I should create another test like ConditionFormTest, which appears to only test the node_type condition. I think that's it. Thanks for the feedback, Jason
Comment #8
aviral2809 commentedI am working on this issue.
Comment #9
aviral2809 commented<?php
namespace Drupal\Tests\block\Functional;
//namespace Drupal\simpletest;
use \Drupal\Tests\BrowserTestBase;
use \Behat\Mink\WebAssert;
/**
* Tests that the blocked page's visibility paths are validated, using a path without leading forward slash works
*
* @group pages
*/
class ForwardSlashTest extends BrowserTestBase{
protected function setUp() {
parent::setUp();
$this->drupalLogin($this->rootUser);
}
public function testForwardSlash(){
$this->drupalGet('/admin/structure/block/manage/bartik_branding');
$this->submitForm(['visibility[request_path][pages' => 'user/login'], 'Show for the listed pages');
$this->assertText('Paths require a leading forward slash when used with the Pages setting.');
}
public function checkRenderingTest(){
$this->assertSession()->elementExists('css', '#bartik_branding');
}
}
Comment #10
aviral2809 commentedComment #11
tameeshb commentedChange issue status to "needs review" for the testbot to test the patch.
Comment #12
jasonawantHi,
The issue description describes a solution to patch RequestPath::validateConfigurationForm to validate the paths, but I don't see RequestPath.php in the provided patch anymore. Is this the right patch file? It looks like the patch file includes a lot more changes that what is currently in this issue. Was it created with a diff from a different version of Drupal core by mistake?
Comment #13
moshnoi commentedComment #23
smustgrave commentedRerolled and added tests-only patch.
Comment #24
smustgrave commentedDidn't realize the tests were incomplete.
Comment #26
Manibharathi E R commentedPatch #24 tested and Applied successfully on Drupal 9.4.x.
Comment #27
charchil khandelwal commentedPatch no. #24 tested and applied successfully on Drupal 9.4.x version.
Comment #37
heni_deepak commentedComment #38
heni_deepak commented#24 patch also working in D9.5
Comment #41
alexpottI think the test would be better if we entered two paths with only the second path missing a leading slash.
I think this should use the same as the logic as the summary method.
The explode "\r\n" looks like it might break on some systems.
strpos($path, '/') === 0should bestr_starts_with($path, '/')- this will work on both D9 and D10 as we have a PHP 8 polyfil.I think the error should contain which path has caused the problem.
Comment #42
smustgrave commentedAddressed the points in #41
41.2 had to use form_state or couldn't get past the error once it triggered.
Comment #44
smustgrave commentedFixed test case
Comment #45
alexpottLet's make this array
$path should be a placeholder in the string. Something like
'%path requires a leading forward slash when used with the Pages setting.'Comment #46
smustgrave commentedAddressed points in #45
Comment #47
alexpottI don't think the quotes are necessary. The % wraps the text in em tags already. I think this is inline with other validation messages.
Comment #48
narendra.rajwar27Updating patch as suggested in comment #47
Comment #50
smustgrave commented@narendra.rajwar27 thank you for the patch but if you are going to contribute please upload an interdiff even for small changes.
Going back to #46
Comment #52
alexpottComment #54
smustgrave commentedQueuing for 10.1.x tests.
Comment #55
sonam.chaturvedi commentedVerified and tested patch #50 on 10.1.x-dev. Patch applied successfully.
Test Steps:
1. Goto Structure > Block Layout
2. Configure any block and select "Pages" tab under Visibility
3. Enter following URL paths - , valid page and "user/login"
4. Click "Save block"
Test Result: Proper validation error message is shown for missing leading forward slash specifying the URL path giving error.
Question: This works only for first path having missing leading forward slash. Should it display all the paths having missing forward slash ?
Comment #56
larowlanThe else does nothing here, so let's drop it and the return for simplicity sake, less code++.
There's a new string here, so I think that makes this 10.1.x only, tagging as such
Comment #57
smustgrave commentedRemoved else
Comment #58
larowlanThis looks RTBC to me now, assuming the bot agrees
Comment #60
larowlanRandom fail
Comment #62
smustgrave commentedAnother random failure
Comment #64
lauriiiCommitted e47f5e7 and pushed to 10.1.x. Thanks!
Comment #66
kristen polWas looking at this issue and not sure why larowlan and sonam and maybe one or two others didn't get issue credit... but it's closed now so :shrug: :)
Comment #67
lauriiiI believe I didn't credit @sonam.chaturvedi because at the time of #55 there was already automated tests that verified that the message was triggered. I missed that there was a question in the comment which looking at it now probably should have been addressed. I opened a follow-up for that since I think it's a good suggestion for usability #3356462: Validate all invalid paths in block visibility.
We usually give credit for non-trivial code reviews. It's hard to evaluate how substantial a review is but this time it looks like I decided that the feedback from @larowlan wouldn't qualify for the credit.
Comment #68
kristen polThank you for the explanation. I’ll reassess how we decide to do manual testing in the future.
Comment #69
cilefen commentedA contrib module called Block Exclude Pages was relying on the bug behavior.
#3375092: Drupal 10.1 + Rejecting paths not conforming to standard URL's set by Drupal