Problem/Motivation

The path field type has a PathAlias constraint, but it only prevents changing an alias in a pending revision. Alias validity is checked by PathWidget::validateFormElement(), which creates and validates a path_alias entity. Validating the containing entity outside that widget does not perform those checks, so duplicate aliases and aliases without a leading slash can pass validation.

The widget also skips validation when the normalized alias is empty. Entering / on an article’s URL alias field therefore allows the node to be saved. PathAlias::preSave() removes the slash, and the resulting path_alias row has a NULL alias.

Steps to reproduce

On a site with the core Path module enabled:

  1. Create an article using the standard node form.
  2. Enter / in its URL alias field and save.
  3. Inspect the corresponding path_alias row: the row exists, but its alias is NULL.

Proposed resolution

  • Validate aliases through the path field independently of its widget, using the value that would actually be stored.
  • Expose a public alias-normalization method shared by PathAlias::preSave(), the widget, and contrib callers.
  • Report a clear validation error for aliases consisting only of slashes.

Remaining tasks

Decide how this relates to or supersedes the existing issues. There are quite a few!

#2350135: Duplicate path aliases can be added concerns a gap within the uniqueness check itself. #3100350: Unable to save '/' root path alias and #3394691: setting path alias to `/` causes PHP8.1/str_starts_with/null error concern / aliases, while #3145132: PathAlias::preSave() should also trim the path, not just the alias concerns source-path normalization. Those issues overlap with parts of this report, but do not address the broader field-validation gap.

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet


AI disclosure: I used Claude Code with Opus 5.5 and Pi with GPT-6 Astra to research and reproduce this bug while authoring MR !1994 for Canvas. This issue description was also produced as part of that work prior to careful editing by me.

Issue fork drupal-3638830

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:

Comments

balintbrews created an issue. See original summary.

balintbrews’s picture

Issue summary: View changes

wim leers’s picture