From bb37af807d03f615024b2261aea50ebf243e9323 Mon Sep 17 00:00:00 2001 From: isaosano Date: Thu, 16 Oct 2014 15:34:14 +0900 Subject: [PATCH 1/2] add testcases for op_auto_link_text (refs #3707, 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 281c6fd9ba947b197d4a560e3c3f4d7762a21662 Mon Sep 17 00:00:00 2001 From: isaosano Date: Thu, 16 Oct 2014 15:44:30 +0900 Subject: [PATCH 2/2] fix SF_AUTO_LINK_RE matches unexpected characters (fixes #3707, BP from #3289) --- lib/helper/opUtilHelper.php | 14 +++++++------- test/unit/helper/opUtilHelperTest.php | 2 ++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/helper/opUtilHelper.php b/lib/helper/opUtilHelper.php index 5a17e9930..bf9c7a155 100644 --- a/lib/helper/opUtilHelper.php +++ b/lib/helper/opUtilHelper.php @@ -311,24 +311,24 @@ 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_\-\/.,:;\~\?@&=+$%#!()]* ) - ([[:punct:]]|\s|<|$) # trailing text - ~x'); + ([^a-zA-Z0-9_\-\/.,:;\~\?@&=+$%#!()]|\ |<|$) # trailing text + ~xu'); } function op_url_cmd($text) 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.