Homepage links become unrelated asset references when filesystem base URL matches site URL

Abierto Apto para principiantes
#24 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
74/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
php
Área
backend

Línea de trabajo

Empieza en HtmlField::serializeValue(), donde la conversión de URL normales recoge las URL raíz del sistema de archivos con $fs->getRootUrl(); sigue la rama de volumen cuando el enlace es igual a la URL base del sitio y al quitar la URL base $uri queda vacío. Confirma que los valores vacíos de filename y folderPath llegan a la consulta de assets, luego añade el guard temprano en esa rama y vuelve a ejecutar la comprobación de serialización de CKEditor. Hecho significa que los enlaces de la página de inicio con y sin barra final, un enlace externo y una URL de imagen existente conservan sus destinos a través de serializaciones repetidas.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug repo:html-field
Description

Saving an absolute homepage link with a trailing slash in a CKEditor field can replace its destination with an unrelated image asset, while leaving the visible link text unchanged. This reproduces with a normal control-panel save, without Feed Me or an external import.

Steps to reproduce

Configuration used in the affected installation (example domain):

  • Site base URL: http://example.test/.
  • Local filesystem: base path @webroot, public URLs enabled, base URL equal to the site base URL.
  • Asset volumes use that filesystem with subpaths such as resources/projects and assets, and contain existing images.
  1. Insert <p><a href="http://example.test/">http://example.test/</a></p> into a CKEditor field. Ensure the destination includes the trailing slash.
  2. Save the entry.
  3. Reopen the entry or inspect the link destination on the rendered page.

Expected: the link still points to http://example.test/.

Actual: the destination becomes an unrelated image in an asset volume. The visible text is unchanged. The field stores a reference like {asset:218:url||http://example.test/} (the selected asset varies by installation).

Reproduced in both job-description and announcement fields. An external-domain homepage link survives locally; using the local site domain reproduces the problem.

Investigation

In HtmlField::serializeValue(), regular-URL conversion collects filesystem root URLs using $fs->getRootUrl(). When the link equals that root URL and reaches the volume branch, removing the base URL leaves $uri === "". Both basename($uri) and dirname($uri) are then empty.

The asset query receives empty filename and folderPath values. Craft’s AssetQuery only adds those filters when their values are truthy, so the lookup can select an unrelated asset in the volume and replace the homepage URL with its reference.

Tested local workaround

Adding this guard in the volume branch prevents the empty-path lookup while leaving site-entry matching intact:

                         } else {
+                            // A filesystem root is not an asset. Empty query filters would match any file.
+                            if ($uri === '') {
+                                continue;
+                            }
+
                             // volume URL
                             $filename = basename($uri);
                             $folderPath = dirname($uri);

A local check using the actual CKEditor field serialization reproduced the incorrect asset reference before the patch. After applying it to HTML Field 3.6.1, homepage links with and without a trailing slash, an external link, and an existing image URL retained their destinations, including after repeated serialization. This is a narrowly scoped workaround, rather than a claim to resolve all volume-subpath matching cases.

Additional info
  • Craft CMS: 5.12.1
  • CKEditor: 5.9.0
  • craftcms/html-field: 3.6.1
  • PHP CLI used for the serialization check: 8.4.27
  • Database driver: MySQL
  • Local environment: macOS / Laravel Herd

Originally observed with Craft 5.9.11, CKEditor 4.11.0 and HTML Field 3.4.0. Updating to the versions above did not resolve it.

Lenguaje dominante
PHP
Estrellas
6
Forks
4
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Issues similares

Más issues de PHP

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.