Skip to content

Commit

Permalink
Merge pull request #1685 from dereuromark/master-autolink
Browse files Browse the repository at this point in the history
Test to prove that autoLink has issues with umlauts.
  • Loading branch information
markstory committed Sep 27, 2013
2 parents 066e0b6 + bd87ef4 commit 355e2ef
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
26 changes: 22 additions & 4 deletions lib/Cake/Test/Case/View/Helper/TextHelperTest.php
Expand Up @@ -241,6 +241,14 @@ public static function autoLinkProvider() {
'Text with a url http://www.not--work.com and more',
'Text with a url <a href="http://www.not--work.com">http://www.not--work.com</a> and more',
),
array(
'Text with a partial www.küchenschöhn-not-working.de URL',
'Text with a partial <a href="http://www.küchenschöhn-not-working.de">www.küchenschöhn-not-working.de</a> URL'
),
array(
'Text with a partial http://www.küchenschöhn-not-working.de URL',
'Text with a partial <a href="http://www.küchenschöhn-not-working.de">http://www.küchenschöhn-not-working.de</a> URL'
)
);
}

Expand Down Expand Up @@ -351,6 +359,16 @@ public function testAutoLinkEmails() {
$expected = 'Text with <a href="mailto:email@example.com" \s*class="link">email@example.com</a> 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 <a href="mailto:düsentrieb@küchenschöhn-not-working.de">düsentrieb@küchenschöhn-not-working.de</a> address';
$result = $this->Text->autoLinkEmails($text);
$this->assertRegExp('#^' . $expected . '$#', $result);

$text = 'Text with me@subdomain.küchenschöhn.de address';
$expected = 'Text with <a href="mailto:me@subdomain.küchenschöhn.de">me@subdomain.küchenschöhn.de</a> address';
$result = $this->Text->autoLinkEmails($text);
$this->assertRegExp('#^' . $expected . '$#', $result);
}

/**
Expand Down Expand Up @@ -383,7 +401,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 <BR id="test"/><br class="test"> test text';
$expected = <<<TEXT
Expand All @@ -392,7 +410,7 @@ public function testAutoParagraph() {
TEXT;
$result = $this->Text->autoParagraph($text);
$this->assertEquals($expected, $result);
$this->assertTextEquals($expected, $result);
$text = <<<TEXT
This is a test text.
This is a line return.
Expand All @@ -403,7 +421,7 @@ public function testAutoParagraph() {
TEXT;
$result = $this->Text->autoParagraph($text);
$this->assertEquals($expected, $result);
$this->assertTextEquals($expected, $result);
$text = <<<TEXT
This is a test text.
Expand All @@ -415,7 +433,7 @@ public function testAutoParagraph() {
TEXT;
$result = $this->Text->autoParagraph($text);
$this->assertEquals($expected, $result);
$this->assertTextEquals($expected, $result);
}

}
6 changes: 3 additions & 3 deletions lib/Cake/View/Helper/TextHelper.php
Expand Up @@ -105,7 +105,7 @@ public function autoLinkUrls($text, $options = array()) {
$this->_placeholders = array();
$options += array('escape' => true);

$pattern = '#(?<!href="|src="|">)((?:https?|ftp|nntp)://[a-z0-9.\-:]+(?:[/?][^\s<]*)?)#i';
$pattern = '#(?<!href="|src="|">)((?:https?|ftp|nntp)://[\p{L}0-9.\-:]+(?:[/?][^\s<]*)?)#ui';
$text = preg_replace_callback(
$pattern,
array(&$this, '_insertPlaceHolder'),
Expand Down Expand Up @@ -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-]+(?:\.[\p{L}0-9-]+)+)/ui',
array(&$this, '_insertPlaceholder'),
$text
);
Expand Down

0 comments on commit 355e2ef

Please sign in to comment.