Nav: link to the site root with an anchor (/#section) gets is_parent on every page
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 35/100
調査の方向性
Read src/Tags/Structure.php around Structure::isParent() and the URL behavior in src/Facades/Endpoint/URL.php; UrlTest::ancestorProvider() is mentioned as covering fragment handling. Compare how the site-root check and ancestor check treat fragments, then add a regression test for /#contact and /de#contact. Done means these links no longer report is_parent on non-home pages; a pull request is already open.
索引モデルが issue の本文から書いたものです。
説明
Bug description
A navigation item that links to the site root with an anchor, like /#contact (or /de#contact on a multisite where the site URL is /de), gets is_parent: true on every page except the home page itself. I'd expect false, the same as an item linking to / without the anchor.
What seems to happen in Structure::isParent():
- The check that stops the home page from being a parent of everything compares the absolute URLs with the fragment still attached.
https://example.com/de#contactisn't equal tohttps://example.com/de, so the check doesn't apply:
https://github.com/statamic/cms/blob/c32098a85ee501bfe577c7d52d42454c5aff0fd5/src/Tags/Structure.php#L302 URL::isAncestorOf()then strips the fragment, so the item's URL becomes/de/, and every page under/de/starts with it:
https://github.com/statamic/cms/blob/c32098a85ee501bfe577c7d52d42454c5aff0fd5/src/Facades/Endpoint/URL.php#L131-L141
isAncestorOf() stripping fragments looks intentional (UrlTest::ancestorProvider() covers it), so the problem is that the two checks treat the fragment differently.
In 5.x, isAncestorOf() didn't strip the fragment from the ancestor, so this didn't happen.
A URL that's only a fragment, like #contact, ends up the same way: it's stripped to /, and the $url === '#' check only catches a bare #.
How to reproduce
-
Create a navigation and use Add → Add Nav Item to add a text link (not "Link to Entry") with the URL
/#contact. -
Output it with the nav tag:
{{ nav:main }} {{ title }}: {{ is_parent ? 'parent' : 'not parent' }} {{ /nav:main }} -
Visit any page other than the home page. The
/#contactitem showsparent.
On a multisite with the site URL /de, the same happens with /de#contact.
Logs
Environment
Environment
Laravel Version: 12.73.0
PHP Version: 8.4.28
Composer Version: 2.11.1
Environment: local
Debug Mode: OFF
Maintenance Mode: OFF
Timezone: UTC
Locale: de_CH
Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED
Drivers
Broadcasting: log
Cache: database
Database: mysql
Logs: stack / daily
Mail: ses
Queue: sync
Session: file
Storage
REMOVED
Locales
Installed: de, de_CH, en, fr, it
LaravelLang\Actions\Plugin: 1.13.1
LaravelLang\Attributes\Plugin: 2.16.3
LaravelLang\HttpStatuses\Plugin: 3.13.1
LaravelLang\Lang\Plugin: 15.31.1
LaravelLang\MoonShine\Plugin: INCORRECT
LaravelLang\StarterKits\Plugin: 1.14.1
Locales Version: 2.11.0
Protected: de, de_CH
Publisher Version: 16.8.0
Livewire
Livewire: v3.8.9
Spatie Permissions
Features Enabled: Default
Version: 6.25.0
Statamic
Addons: 4
License Key: Set
Sites: 3 (REMOVED, REMOVED, REMOVED)
Stache Watcher: Enabled (auto)
Static Caching: Disabled
Version: 6.42.0 PRO
Statamic Addons
marcorieser/statamic-livewire: 5.3.5
stillat/antlers-components: 2.8.0
[REMOVED PRIVATE 1+2]
Installation
Fresh statamic/statamic site via CLI
Additional details
Possible fix in Structure::isParent(): strip the query string and fragment before comparing with the site root, and skip any URL that starts with #:
if (Str::startsWith($url, '#')) {
return false;
}
if ($this->siteAbsoluteUrl === URL::removeQueryAndFragment($absoluteUrl)) {
return false;
}
Workaround for now: {{ if is_parent && ! (url | contains('#')) }} in the template.
Similar to #5269 (empty URLs flagged as parent in 3.2.x).
- 主要言語
- PHP
- スター
- 4.9k
- フォーク
- 647
- 平均マージ
- 1日 45分
- マージ済み PR(30日)
- 221
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
statamic/cms のほかの issue
-
forms ui
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
accessibility
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
メンテナーはふだん 1 日以内に返信
-
antlers
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
メンテナーはふだん 1 日以内に返信
-
Multiple Choice and Checkboxes no longer offer "Inline", but the default views still use it対応中かも @duncanmcclean が今日担当しました。 オープンforms
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
メンテナーはふだん 1 日以内に返信
-
Confusing UX when switching between forms対応中かも @jaygeorge が 1 日前に担当しました。 オープンforms ux
statamic/cms#16047 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
似ている issue
-
sync-en
難易度 1/5 1時間未満 初心者へのやさしさ 86/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
vimeo/psalm#15150 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
taskforcesh/bullmq#5238 ·
メンテナーはふだん 1 日以内に返信
-
[Bug] v-change-database-password reports success but doesn't change the password when MySQL validate_password rejects it対応中かも @bfs2021 が今日担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
Automattic/jetpack#55517 ·
メンテナーはふだん 1 日以内に返信