Ensure Base Path Handling for checkInternalAnchors Function

Created on 24 January 2025, 3 months ago

Problem/Motivation

When using the checkInternalAnchors function to verify URLs in a body field, discrepancies arise in environments where a base path (e.g., /d9dev) is added by the web server (such as Apache2) but is not part of the original URLs stored in the database.

For example:

Production Environment: URLs are stored as href="/node/1".
Development Environment: The site is served under a base path (e.g., /d9dev), requiring links to be prefixed (e.g., href="/d9dev/node/1").
This inconsistency causes the function to fail in detecting and validating relative links in environments where a base path is used.

Steps to reproduce

  • Backport a production database with links in body fields (href="/node/1") to a development environment served under a base path (e.g., /d9dev). Or manually strip the base path from an internal link.
  • Call the checkInternalAnchors function on the body field content.
  • Obs

erve that the function fails to validate the links because the base path is missing from the href.

Proposed resolution

Modify the checkInternalAnchors function to dynamically detect the base path from the request (\Drupal::request()->getBasePath()) and prepend it to the href attribute when necessary. This ensures that links are properly validated regardless of the environment.

Remaining tasks

Review PR and test.

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇨🇦Canada smulvih2 Canada 🍁

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024