At the moment Drupal\path\Plugin\Field\FieldType\PathItem::generateSampleValue() generates a path that doesn't start with a slash causing errors like Alias path demo-alias-without-a-slash. has to start with a slash when saving the node.

I've attached a patch with the fix and a test, also a failing test without the fix.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jeqq created an issue. See original summary.

jeqq’s picture

Status: Active » Needs review
jeqq’s picture

Manuel Garcia’s picture

The fix simple enough, and the test covers the bug, and is easy to follow. Only one nitpick from me:

+++ b/core/modules/path/tests/src/Kernel/PathItemTest.php
@@ -189,6 +189,18 @@ public function testPathItem() {
+ // Test the generateSampleValue() method.

We can make it clearer as to what we are testing here, something like:

Assert that \Drupal\path\Plugin\Field\FieldType\PathItem::generateSampleValue() produces a valid path value.

timmillwood’s picture

Status: Needs review » Reviewed & tested by the community

Nice find @jeqq, looks good to me!

alexpott’s picture

+++ b/core/modules/path/tests/src/Kernel/PathItemTest.php
@@ -189,6 +189,18 @@ public function testPathItem() {
+    $this->assertTrue($node->get('path')->alias[0] === '/');

I'm not that convinced by #5 but this assertion should be:

$this->assertStringStartsWith('/', $node->get('path')->alias);

Since PHPUnit will give far better errors with that.

alexpott’s picture

Version: 8.4.x-dev » 8.5.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed b5a5c68129 to 8.6.x and f4fd08a7e3 to 8.5.x. Thanks!

Backported to 8.5.x since this bug-fix is extremely low risk and tested.

  • alexpott committed b5a5c68 on 8.6.x
    Issue #2944215 by jeqq, alexpott: Aliases generated by PathItem::...

  • alexpott committed f4fd08a on 8.5.x
    Issue #2944215 by jeqq, alexpott: Aliases generated by PathItem::...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.