From 1ebcd9bf72c4ad3b51a30f7b01a468652e64d2e1 Mon Sep 17 00:00:00 2001 From: Rob McVey Date: Fri, 2 Jan 2015 15:08:21 +0000 Subject: [PATCH 1/5] Test brackets are not autolinked inside href tag --- lib/Cake/Test/Case/View/Helper/TextHelperTest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/Cake/Test/Case/View/Helper/TextHelperTest.php b/lib/Cake/Test/Case/View/Helper/TextHelperTest.php index c4e36aaa7..0760c9125 100644 --- a/lib/Cake/Test/Case/View/Helper/TextHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/TextHelperTest.php @@ -146,6 +146,16 @@ class TextHelperTest extends CakeTestCase { $expected = 'This is a test text with URL http://www.cakephp.org(and some more text)'; $result = $this->Text->autoLink($text); $this->assertEquals($expected, $result); + + $text = 'This is a test text with URL (http://www.cakephp.org/page/4) in brackets'; + $expected = 'This is a test text with URL (http://www.cakephp.org/page/4] in square brackets'; + $result = $this->Text->autoLink($text); + $this->assertEquals($expected, $result); } /** From 2bf41f3d8525e2cc684c358b15a624e89578ceb1 Mon Sep 17 00:00:00 2001 From: Rob McVey Date: Fri, 2 Jan 2015 15:09:40 +0000 Subject: [PATCH 2/5] Add missing double quote to link in test --- lib/Cake/Test/Case/View/Helper/TextHelperTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/View/Helper/TextHelperTest.php b/lib/Cake/Test/Case/View/Helper/TextHelperTest.php index 0760c9125..86d669d99 100644 --- a/lib/Cake/Test/Case/View/Helper/TextHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/TextHelperTest.php @@ -148,7 +148,7 @@ class TextHelperTest extends CakeTestCase { $this->assertEquals($expected, $result); $text = 'This is a test text with URL (http://www.cakephp.org/page/4) in brackets'; - $expected = 'This is a test text with URL (http://www.cakephp.org/page/4) in brackets'; $result = $this->Text->autoLink($text); $this->assertEquals($expected, $result); From 54e172b1296f12a2c2c3b6b569c96e6a86d78f3f Mon Sep 17 00:00:00 2001 From: Rob McVey Date: Fri, 2 Jan 2015 15:15:23 +0000 Subject: [PATCH 3/5] Regex modified to to not capture brackets Modified the existing regex from th TLD onwards Credit to @gruber for the regex info https://gist.github.com/gruber/249502 --- lib/Cake/View/Helper/TextHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/View/Helper/TextHelper.php b/lib/Cake/View/Helper/TextHelper.php index 6e9684765..92d30ace6 100644 --- a/lib/Cake/View/Helper/TextHelper.php +++ b/lib/Cake/View/Helper/TextHelper.php @@ -107,7 +107,7 @@ class TextHelper extends AppHelper { $this->_placeholders = array(); $options += array('escape' => true); - $pattern = '#(?)((?:https?|ftp|nntp)://[\p{L}0-9.\-_:]+(?:[/?][^\s<]*)?)#ui'; + $pattern = '#(?)((?:https?|ftp|nntp)://[\p{L}0-9.\-_:]+(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))#i'; $text = preg_replace_callback( $pattern, array(&$this, '_insertPlaceHolder'), From 76b7c8c594b6f67b15a673fe029d0e9035e2e1bd Mon Sep 17 00:00:00 2001 From: Rob McVey Date: Fri, 2 Jan 2015 15:31:27 +0000 Subject: [PATCH 4/5] More complex test case for GET params --- lib/Cake/Test/Case/View/Helper/TextHelperTest.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/Cake/Test/Case/View/Helper/TextHelperTest.php b/lib/Cake/Test/Case/View/Helper/TextHelperTest.php index 86d669d99..63cd79494 100644 --- a/lib/Cake/Test/Case/View/Helper/TextHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/TextHelperTest.php @@ -156,6 +156,11 @@ class TextHelperTest extends CakeTestCase { $expected = 'This is a test text with URL [http://www.cakephp.org/page/4] in square brackets'; $result = $this->Text->autoLink($text); $this->assertEquals($expected, $result); + + $text = 'This is a test text with URL [http://www.example.com?aParam[]=value1&aParam[]=value2&aParam[]=value3] in square brackets'; + $expected = 'This is a test text with URL [http://www.example.com?aParam[]=value1&aParam[]=value2&aParam[]=value3] in square brackets'; + $result = $this->Text->autoLink($text); + $this->assertEquals($expected, $result); } /** From b6029d7ad1377beb2050022d27c31a900e985a63 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 3 Jan 2015 14:30:56 -0500 Subject: [PATCH 5/5] Add some additional tests for autoLink. Refs #5544 --- lib/Cake/Test/Case/View/Helper/TextHelperTest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/Cake/Test/Case/View/Helper/TextHelperTest.php b/lib/Cake/Test/Case/View/Helper/TextHelperTest.php index 63cd79494..41ef4b296 100644 --- a/lib/Cake/Test/Case/View/Helper/TextHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/TextHelperTest.php @@ -161,6 +161,16 @@ class TextHelperTest extends CakeTestCase { $expected = 'This is a test text with URL [http://www.example.com?aParam[]=value1&aParam[]=value2&aParam[]=value3] in square brackets'; $result = $this->Text->autoLink($text); $this->assertEquals($expected, $result); + + $text = 'This is a test text with URL ;http://www.cakephp.org/page/4; semi-colon'; + $expected = 'This is a test text with URL ;http://www.cakephp.org/page/4; semi-colon'; + $result = $this->Text->autoLink($text); + $this->assertEquals($expected, $result); + + $text = 'This is a test text with URL (http://www.cakephp.org/page/4/other(thing)) brackets'; + $expected = 'This is a test text with URL (http://www.cakephp.org/page/4/other(thing)) brackets'; + $result = $this->Text->autoLink($text); + $this->assertEquals($expected, $result); } /**