From 61151cc5c2e77f29668834154bf9281cdd92fa53 Mon Sep 17 00:00:00 2001 From: sakaguchi Date: Tue, 2 Jun 2026 22:13:38 +0900 Subject: [PATCH] =?UTF-8?q?fix=20#4001=20=E3=83=96=E3=83=AD=E3=82=B0?= =?UTF-8?q?=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88=E7=AE=A1=E7=90=86=EF=BC=9A?= =?UTF-8?q?=E6=96=87=E5=AD=97=E8=89=B2=E3=81=AE=E7=9B=B8=E9=81=95=E3=81=8C?= =?UTF-8?q?=E3=81=82=E3=82=8B=E4=BB=B6=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/View/Helper/BcTextHelper.php | 51 +++++++++++++++++++ .../TestCase/View/Helper/BcTextHelperTest.php | 18 +++++++ 2 files changed, 69 insertions(+) diff --git a/plugins/baser-core/src/View/Helper/BcTextHelper.php b/plugins/baser-core/src/View/Helper/BcTextHelper.php index f8c91ee050..eb3182017e 100644 --- a/plugins/baser-core/src/View/Helper/BcTextHelper.php +++ b/plugins/baser-core/src/View/Helper/BcTextHelper.php @@ -475,4 +475,55 @@ public function booleanStatus($value) } // <<< + /** + * テキスト内のURLを自動でリンク化 + * + * CakePHP本体の autoLinkUrls() では、ドメインのみURLの末尾スラッシュが + * リンク外に出るケースがあるため、リンク直後のスラッシュだけ補正する。 + * + * @param string $text テキスト + * @param array $options リンクオプション + * @return string リンク化後テキスト + * @checked + * @noTodo + * @unitTest + */ + public function autoLinkUrls(string $text, array $options = []): string + { + $linkedText = parent::autoLinkUrls($text, $options); + + return $this->fixTrailingSlashOutsideAnchor($linkedText); + } + + /** + * ドメインのみURLで末尾スラッシュがリンク外に出る表示崩れを補正 + * + * @param string $text リンク化後テキスト + * @return string 補正後テキスト + */ + protected function fixTrailingSlashOutsideAnchor(string $text): string + { + // 壊れたパターンだけを対象に補正する。 + // 例: https://example.com/ + // + // (?) : href 属性より前の属性群(class, target など) + // (?) : href 値(スキーム + ドメインのみ。末尾スラッシュなし) + // (?) : href 属性より後の属性群 + // (?