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
checkInternalAnchorsfunction 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.
Comments
Comment #2
smulvih2PR: https://git.drupalcode.org/project/safedelete/-/merge_requests/8
The following changes were made:
Comment #3
joseph.olstad