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

Aperta Adatta ai principianti
#24 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
74/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
php
Ambito
backend

Direzione di ricerca

Inizia in HtmlField::serializeValue(), dove la conversione degli URL regolari raccoglie gli URL root del filesystem con $fs->getRootUrl(); segui il branch volume quando il link è uguale all'URL base del sito e la rimozione dell'URL base lascia $uri vuoto. Verifica che valori filename e folderPath vuoti arrivino alla query degli asset, poi aggiungi l'early guard in quel branch ed esegui di nuovo il controllo di serializzazione CKEditor. Completo significa che i link della homepage con e senza slash finale, un link esterno e un URL di immagine esistente mantengono le loro destinazioni attraverso serializzazioni ripetute.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
PHP
Stelle
6
Fork
4
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.