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

オープン 初心者向け
#24 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
74/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
php
領域
backend

調査の方向性

HtmlField::serializeValue() から始める。ここでは通常 URL の変換がファイルシステムのルート URL を $fs->getRootUrl() で収集している。リンクがサイトのベース URL と等しく、ベース URL を除去すると $uri が空になる場合の volume 分岐をたどる。空の filename と folderPath の値が asset のクエリに到達することを確認し、その分岐に早期 guard を追加して、CKEditor のシリアライズチェックを再実行する。完了条件は、末尾スラッシュありとなしのホームページリンク、外部リンク、および既存の画像 URL が、繰り返しのシリアライズを通じても遷移先を保持していること。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
PHP
スター
6
フォーク
4
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

似ている issue

PHP の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。