プロジェクト

全般

プロフィール

Backport(バックポート) #2734

Yuya Watanabe約12年前に更新

h3. Overview (現象)

半角空白区切りの連続した複数のURLが正常に自動リンクされない

h4. 詳細

日記本文で現象を確認

h5. 書き込み内容

<pre>
http://example.com/ http://example.com/hoge http://example.com/fuga http://example.com/hoge
</pre>

h5. ブラウザ出力結果(HTML)

<pre>
<div class="title">
<p class="heading">test</p>
</div>
<div class="body">
<a href="http://example.com/" target="_blank">http://example.com/</a> http://example.com/hoge <a href="http://example.com/fuga" target="_blank">http://example.com/fuga</a> http://example.com/hoge</div>
</dd>
</dl>
</pre>



h3. Causes (原因)

リンクを生成する際に URL を正規表現でマッチさせているが,これがプレフィックスとして空白文字を考慮していない.

lib/helper/opUtilHelper.php 313-317行目
<pre>
310 if (!defined('SF_AUTO_LINK_RE'))
311 {
312 define('SF_AUTO_LINK_RE', '~
313 ( # leading text
314 <\w+.*?>| # leading HTML tag, or
315 [^=!:\'"/]| # leading punctuation, or
316 ^ # beginning of line, or
317 )
318 (
319 (?:https?://)| # protocol spec, or
320 (?:www\.) # www.*
321 )
322 (
323 [-\w]+ # subdomain or domain
324 (?:\.[-\w]+)* # remaining subdomains or domain
325 (?::\d+)? # port
326 \/?
327 [a-zA-Z0-9_\-\/.,:;\~\?@&=+$%#!()]*
328 )
329 ([[:punct:]]|\s|<|$) # trailing text
330 ~x');
331 }
</pre>

h3. Way to fix (修正内容)

正規表現で URL にマッチさせる際に空白文字を考慮する.

<pre>

diff --git a/lib/helper/opUtilHelper.php b/lib/helper/opUtilHelper.php
index 59d22bc..d918493 100644
--- a/lib/helper/opUtilHelper.php
+++ b/lib/helper/opUtilHelper.php
@@ -313,7 +313,8 @@ if (!defined('SF_AUTO_LINK_RE'))
( # leading text
<\w+.*?>| # leading HTML tag, or
[^=!:\'"/]| # leading punctuation, or
- ^ # beginning of line
+ ^| # beginning of line, or
+ \s? # leading whitespaces
)
(
(?:https?://)| # protocol spec, or
</pre>

戻る