From c0409003a02a91b619e61fa6447a02d5dd3e50c7 Mon Sep 17 00:00:00 2001 From: isaosano Date: Thu, 16 Oct 2014 18:04:03 +0900 Subject: [PATCH 1/2] add testcases for op_auto_link_text (refs #3708, BP from #3289) --- test/unit/helper/opUtilHelperTest.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/unit/helper/opUtilHelperTest.php b/test/unit/helper/opUtilHelperTest.php index ab5aa5a7e..4e08cacfe 100644 --- a/test/unit/helper/opUtilHelperTest.php +++ b/test/unit/helper/opUtilHelperTest.php @@ -75,3 +75,21 @@ Doctrine::getTable('SnsConfig')->set('nickname_of_member_who_does_not_have_credentials', 'I am a pen.'); $t->is(op_link_to_member(null), 'I am a pen.', 'set nickname_of_member_who_does_not_have_credentials original setting'); + +//------------------------------------------------------------ +$t->diag('op_auto_link_text()'); +$t->is(op_auto_link_text('http://example.com/'), 'http://example.com/'); +$t->is(op_auto_link_text('https://example.com/'), 'https://example.com/', 'protocol'); +$t->is(op_auto_link_text('http://sub.example.com/'), 'http://sub.example.com/', 'subdomain'); +$t->is(op_auto_link_text('http://example.com/hoge'), 'http://example.com/hoge', 'path'); +$t->is(op_auto_link_text('http://example.com:8080/'), 'http://example.com:8080/', 'port'); +$t->is(op_auto_link_text('http://example.com/#foo'), 'http://example.com/#foo', 'anchor'); +$t->is(op_auto_link_text('http://example.com/?foo=1&bar=0'), 'http://example.com/?foo=1&bar=0', 'query'); +$t->is(op_auto_link_text('https://sub.example.com:8080/hoge?foo=1&bar=0#foo'), 'https://sub.example.com:8080/hoge?foo=1&bar=0#foo'); +$t->is(op_auto_link_text('http://example.com'), 'http://example.com'); +$t->is(op_auto_link_text('www.example.com'), 'www.example.com'); +// see https://trac.openpne.jp/ticket/3553 +$t->is(op_auto_link_text('http://example.com/#comment:1'), 'http://example.com/#comment:1'); +// see https://redmine.openpne.jp/issues/3289 +$t->is(op_auto_link_text('http://example.com/テキスト'), 'http://example.com/テキスト'); +$t->is(op_auto_link_text('http://example.comテキスト'), 'http://example.comテキスト'); From c70b740b32f5dede1b82a67588c1d0e20e395e39 Mon Sep 17 00:00:00 2001 From: isaosano Date: Thu, 16 Oct 2014 18:06:57 +0900 Subject: [PATCH 2/2] fix SF_AUTO_LINK_RE matches unexpected characters (fixes #3708, BP from #3289) --- lib/helper/opUtilHelper.php | 12 ++++++------ test/unit/helper/opUtilHelperTest.php | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/helper/opUtilHelper.php b/lib/helper/opUtilHelper.php index eecc76299..78b91f79c 100644 --- a/lib/helper/opUtilHelper.php +++ b/lib/helper/opUtilHelper.php @@ -312,23 +312,23 @@ function op_format_date($date, $format = 'd', $culture = null, $charset = null) { define('SF_AUTO_LINK_RE', '~ ( # leading text - <\w+.*?>| # leading HTML tag, or + <[0-9A-Za-z]+.*?>| # leading HTML tag, or [^=!:\'"/]| # leading punctuation, or ^| # beginning of line, or - \s? # leading whitespaces + \ ? # leading whitespaces ) ( (?:https?://)| # protocol spec, or (?:www\.) # www.* ) ( - [-\w]+ # subdomain or domain - (?:\.[-\w]+)* # remaining subdomains or domain - (?::\d+)? # port + [-0-9A-Za-z]+ # subdomain or domain + (?:\.[-0-9A-Za-z]+)* # remaining subdomains or domain + (?::[0-9]+)? # port \/? [a-zA-Z0-9_\-\/.,:;\~\?@&=+$%#!()]* ) - ([^a-zA-Z0-9_\-\/.,:;\~\?@&=+$%#!()]|\s|<|$) # trailing text + ([^a-zA-Z0-9_\-\/.,:;\~\?@&=+$%#!()]|\ |<|$) # trailing text ~xu'); } diff --git a/test/unit/helper/opUtilHelperTest.php b/test/unit/helper/opUtilHelperTest.php index 4e08cacfe..7e2eeeb83 100644 --- a/test/unit/helper/opUtilHelperTest.php +++ b/test/unit/helper/opUtilHelperTest.php @@ -92,4 +92,6 @@ $t->is(op_auto_link_text('http://example.com/#comment:1'), 'http://example.com/#comment:1'); // see https://redmine.openpne.jp/issues/3289 $t->is(op_auto_link_text('http://example.com/テキスト'), 'http://example.com/テキスト'); +$t->is(op_auto_link_text('http://example.com/hogeテキスト'), 'http://example.com/hogeテキスト'); $t->is(op_auto_link_text('http://example.comテキスト'), 'http://example.comテキスト'); +$t->is(op_auto_link_text('http://example.com:8080/'), 'http://example.com:8080/'); // http://example.com:/ is valid URI.