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 属性より後の属性群 + // (?