Homepage links become unrelated asset references when filesystem base URL matches site URL
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 74/100
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
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/projectsandassets, and contain existing images.
- Insert
<p><a href="http://example.test/">http://example.test/</a></p>into a CKEditor field. Ensure the destination includes the trailing slash. - Save the entry.
- 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
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Issues similares
-
Document lexicon.default.userconfig and lexicon.default.userconfig.enforced in config.sample.phpAbiertoenhancement feature: settings good first issue
Dificultad 1/5 1-3 horas Aptitud para principiantes 88/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
nextcloud/integration_openai#480 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Los mantenedores suelen responder en 1 día
-
a11y
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
omeka/plugin-Contribution#84 ·
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
recca0120/vscode-phpunit#620 ·
Los mantenedores suelen responder en 1 día