From 2a954b6095ff680d3b7672339166492e0e03ceb3 Mon Sep 17 00:00:00 2001 From: euromark Date: Fri, 27 Sep 2013 14:48:57 +0200 Subject: [PATCH 1/3] Make TextHelper::autoLink() work properly with umlauts. --- .../Test/Case/View/Helper/TextHelperTest.php | 16 ++++++++++++---- lib/Cake/View/Helper/TextHelper.php | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/Cake/Test/Case/View/Helper/TextHelperTest.php b/lib/Cake/Test/Case/View/Helper/TextHelperTest.php index 887f84372b2..1bb27f4650d 100644 --- a/lib/Cake/Test/Case/View/Helper/TextHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/TextHelperTest.php @@ -241,6 +241,14 @@ public static function autoLinkProvider() { 'Text with a url http://www.not--work.com and more', 'Text with a url http://www.not--work.com and more', ), + array( + 'Text with a partial www.küchenschöhn-not-working.de URL', + 'Text with a partial www.küchenschöhn-not-working.de URL' + ), + array( + 'Text with a partial http://www.küchenschöhn-not-working.de URL', + 'Text with a partial http://www.küchenschöhn-not-working.de URL' + ) ); } @@ -383,7 +391,7 @@ public function testAutoParagraph() { TEXT; $result = $this->Text->autoParagraph($text); - $this->assertEquals($expected, $result); + $this->assertTextEquals($expected, $result); $result = $this->Text->autoParagraph($text); $text = 'This is a

test text'; $expected = <<Text->autoParagraph($text); - $this->assertEquals($expected, $result); + $this->assertTextEquals($expected, $result); $text = <<Text->autoParagraph($text); - $this->assertEquals($expected, $result); + $this->assertTextEquals($expected, $result); $text = <<Text->autoParagraph($text); - $this->assertEquals($expected, $result); + $this->assertTextEquals($expected, $result); } } diff --git a/lib/Cake/View/Helper/TextHelper.php b/lib/Cake/View/Helper/TextHelper.php index 379c89582a8..96d6d709893 100644 --- a/lib/Cake/View/Helper/TextHelper.php +++ b/lib/Cake/View/Helper/TextHelper.php @@ -105,7 +105,7 @@ public function autoLinkUrls($text, $options = array()) { $this->_placeholders = array(); $options += array('escape' => true); - $pattern = '#(?)((?:https?|ftp|nntp)://[a-z0-9.\-:]+(?:[/?][^\s<]*)?)#i'; + $pattern = '#(?)((?:https?|ftp|nntp)://[\p{L}0-9.\-:]+(?:[/?][^\s<]*)?)#ui'; $text = preg_replace_callback( $pattern, array(&$this, '_insertPlaceHolder'), From 205f7a504bc73dc86fcaa5a593d7b6a426112223 Mon Sep 17 00:00:00 2001 From: euromark Date: Fri, 27 Sep 2013 14:56:53 +0200 Subject: [PATCH 2/3] also fix autoLinkEmail() --- lib/Cake/Test/Case/View/Helper/TextHelperTest.php | 5 +++++ lib/Cake/View/Helper/TextHelper.php | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Test/Case/View/Helper/TextHelperTest.php b/lib/Cake/Test/Case/View/Helper/TextHelperTest.php index 1bb27f4650d..e620c13b970 100644 --- a/lib/Cake/Test/Case/View/Helper/TextHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/TextHelperTest.php @@ -359,6 +359,11 @@ public function testAutoLinkEmails() { $expected = 'Text with email@example.com address'; $result = $this->Text->autoLinkEmails($text, array('class' => 'link')); $this->assertRegExp('#^' . $expected . '$#', $result); + + $text = 'Text with düsentrieb@küchenschöhn-not-working.de address'; + $expected = 'Text with düsentrieb@küchenschöhn-not-working.de address'; + $result = $this->Text->autoLinkEmails($text); + $this->assertRegExp('#^' . $expected . '$#', $result); } /** diff --git a/lib/Cake/View/Helper/TextHelper.php b/lib/Cake/View/Helper/TextHelper.php index 96d6d709893..b979ec61771 100644 --- a/lib/Cake/View/Helper/TextHelper.php +++ b/lib/Cake/View/Helper/TextHelper.php @@ -186,9 +186,9 @@ public function autoLinkEmails($text, $options = array()) { $options += array('escape' => true); $this->_placeholders = array(); - $atom = '[a-z0-9!#$%&\'*+\/=?^_`{|}~-]'; + $atom = '[\p{L}0-9!#$%&\'*+\/=?^_`{|}~-]'; $text = preg_replace_callback( - '/(' . $atom . '+(?:\.' . $atom . '+)*@[a-z0-9-]+(?:\.[a-z0-9-]+)+)/i', + '/(' . $atom . '+(?:\.' . $atom . '+)*@[\p{L}0-9-]+(?:\.[a-z0-9-]+)+)/ui', array(&$this, '_insertPlaceholder'), $text ); From bd87ef45f2b36e35e806082623792d91b30ca639 Mon Sep 17 00:00:00 2001 From: euromark Date: Fri, 27 Sep 2013 15:01:46 +0200 Subject: [PATCH 3/3] complete autoLinkEmail() --- lib/Cake/Test/Case/View/Helper/TextHelperTest.php | 5 +++++ lib/Cake/View/Helper/TextHelper.php | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/View/Helper/TextHelperTest.php b/lib/Cake/Test/Case/View/Helper/TextHelperTest.php index e620c13b970..2fc6f21ab7e 100644 --- a/lib/Cake/Test/Case/View/Helper/TextHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/TextHelperTest.php @@ -364,6 +364,11 @@ public function testAutoLinkEmails() { $expected = 'Text with düsentrieb@küchenschöhn-not-working.de address'; $result = $this->Text->autoLinkEmails($text); $this->assertRegExp('#^' . $expected . '$#', $result); + + $text = 'Text with me@subdomain.küchenschöhn.de address'; + $expected = 'Text with me@subdomain.küchenschöhn.de address'; + $result = $this->Text->autoLinkEmails($text); + $this->assertRegExp('#^' . $expected . '$#', $result); } /** diff --git a/lib/Cake/View/Helper/TextHelper.php b/lib/Cake/View/Helper/TextHelper.php index b979ec61771..ffa89b54361 100644 --- a/lib/Cake/View/Helper/TextHelper.php +++ b/lib/Cake/View/Helper/TextHelper.php @@ -188,7 +188,7 @@ public function autoLinkEmails($text, $options = array()) { $atom = '[\p{L}0-9!#$%&\'*+\/=?^_`{|}~-]'; $text = preg_replace_callback( - '/(' . $atom . '+(?:\.' . $atom . '+)*@[\p{L}0-9-]+(?:\.[a-z0-9-]+)+)/ui', + '/(' . $atom . '+(?:\.' . $atom . '+)*@[\p{L}0-9-]+(?:\.[\p{L}0-9-]+)+)/ui', array(&$this, '_insertPlaceholder'), $text );