Homepage links become unrelated asset references when filesystem base URL matches site URL
まだ誰も着手していません。
評価
調査の方向性
HtmlField::serializeValue() から始める。ここでは通常 URL の変換がファイルシステムのルート URL を $fs->getRootUrl() で収集している。リンクがサイトのベース URL と等しく、ベース URL を除去すると $uri が空になる場合の volume 分岐をたどる。空の filename と folderPath の値が asset のクエリに到達することを確認し、その分岐に早期 guard を追加して、CKEditor のシリアライズチェックを再実行する。完了条件は、末尾スラッシュありとなしのホームページリンク、外部リンク、および既存の画像 URL が、繰り返しのシリアライズを通じても遷移先を保持していること。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- PHP
- スター
- 6
- フォーク
- 4
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
似ている issue
-
Document lexicon.default.userconfig and lexicon.default.userconfig.enforced in config.sample.phpオープンenhancement feature: settings good first issue
難易度 1/5 1〜3時間 初心者へのやさしさ 88/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
nextcloud/integration_openai#480 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
メンテナーはふだん 1 日以内に返信
-
a11y
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
omeka/plugin-Contribution#84 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
recca0120/vscode-phpunit#620 ·
メンテナーはふだん 1 日以内に返信