Problem/Motivation
Drupal Core since Drupal 8 uses a leading slash in path fields, e.g. Node path alias, custom menu items, ...
Some modules, especially coming from Drupal 7 break with the new standard.
Sadly Pathauto as a very widely used module also breaks with it in the path pattern.
This should be fixed to validate the path pattern to start with a leadings slash.
Steps to reproduce
Enter a path pattern without a leading slash, e.g. faq/[node:title].
The form can be saved without an error and the value is also saved and displayed without a leading slash.
Adding a leading slash also works, which makes it even unclear what's expected and which side-effects this might have!
Proposed resolution
- Add the core description to the "Path pattern" input field
- Add a validation for the leading slash, like for other path fields in core. If the leading slash is missing, reject the submission. The core error message is: "The alias path has to start with a slash."
- Add an update hook to transform all path patterns to use the leading slash. Ensure that this won't result in double leading slashes, by
ltrim('/')'ing the value first - Ensure the migration also adds a leading slash when upgrading from earlier Drupal versions
See the implementations here: https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/path_...
As a common module, pathauto should act as role model for other modules here.
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork pathauto-3466282
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
sourav_paulComment #3
anybodyDid some initial implementation, feel free to proceed! :)
Comment #5
sourav_paulComment #6
anybody@Sourav_Paul tests still fail and there's a lot of work to do. Changing a word isn't a big deal here, sorry. But thank you anyway.
Comment #7
lrwebks commentedComment #8
lrwebks commentedComment #9
anybody@lrwebks thanks! Some points:
1. Pipeline is red, while it's green on the project page, that looks wrong?
2. Shouldn't the value be validated in the form?
Comment #10
lrwebks commented@anybody regarding #9
pathauto_pattern_validate()from thepathauto.modulefile is called from the form via the following line inPatternEditForm.php:The other checks for missing tokens and whitespace at the end of the path were already placed in the
pathauto_pattern_validate()function, which is why I placed the new check there as well. I suppose that we could try to move this whole functionality over to the form if it is not used by any other part of the module, but the current implementation works fine right now.Comment #11
lrwebks commentedWell, the failing test was green locally, so I decided to try to run another pipeline, and: No more fails! Seems weird to me though, as I did not update the fork or anything similar in between pipelines, so this feels like a weird PHPUnit hiccup… It could be related to the fact that the failed FunctionalJavascript test seems to use the
waitForElementVisible()function a lot, which can fail randomly if the page loading takes too long.Anyway, back to review!
Comment #12
lrwebks commentedComment #13
berdirThe answer should be "no side effects", generated aliases will always have a leading /.
Instead of failing with an error, we could just ensure the / is always there and add it on save?
Also not sure this is a bug, this just makes things a bit more consistent in the pathauto UI.
Comment #14
anybodyThanks for the feedback @berdir. :)
Yes, I remember Drupal 8 made this switch in several cases in core, forcing to start with a leading slash, which was unclear in Drupal 7- And I think it's a good idea for consistency = usability. So I'd clearly vote to do the same in all Drupal 8+ modules, even if it's not a clear bug.
Comment #15
grevil commentedI agree with @berdir here. Instead of throwing a validation error, we should simply add a leading slash to the pathauto pattern on submit, if none exists, instead of throwing a validation error here!
Comment #16
dalemoore commentedI'm in favor of consistently including the leading slash, I just noticed that in this new site I am working on I've included it in some patterns and excluded it in others. As long as it silently adds it on save but continues to work for existing patterns without (or maybe updates existing ones on sav of the Patterns page, or in a module update hook) it sounds like a nice feature to improve consistency.
Comment #17
anybodyYes, I also agree with #13!
Comment #18
lrwebks commentedWorks fine now, pipeline currently fails because of some server error when composer pulls packages (cloudflare outage, probably temporary).
Comment #19
lrwebks commentedComment #20
anybodyGreat @lrwebks! All green now with Cloudflare back at work :)
Comment #21
grevil commentedLGTM, and works as expected, just added a few comments regarding the tests.
Comment #22
anybodyNice, thanks for the feedback! @lrwebks please finish :)
Comment #23
lrwebks commentedComment #24
anybodyI still see a lot of yellow and red in the pipeline, please fix the related things. And especially the test(s)
Comment #25
lrwebks commentedFork update seems to have resolved the pipeline again, so the failure was unrelated.
Comment #26
lrwebks commented@berdir, since I can't resolve the MR threads myself, could you do that (if what we talked about is actually resolved of course)? Pipeline is green again.
Comment #27
mably commentedComment #28
mably commentedAdded the leading slash fix to this issue's MR: #2728725: Special characters like tab or spaces in pattern can break alias generation
Comment #29
mably commentedComment #30
anybodyThx @mably let's wait for @berdir's feedback on how to proceed here and finish this.
Comment #31
berdirAgreed with no update function needed here, and yeah, the other MR now covers this and this is essentially a duplicate. Don't forget to transfer contributions over (I'd close as duplicate instead of marking as fixed, for posterity and generated release notes)
Comment #32
anybodyThanks for pushing things forward here with us @mably and @berdir! I'm very happy to see #2728725: Special characters like tab or spaces in pattern can break alias generation is close to the finish line! 🎉
THANK YOU!
Comment #33
mably commentedClosed as duplicate of #2728725.
Thanks everybody!