mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Fixing TextHelper::autoLinkEmails() not linking email addresses that contain '.
Test added. Fixes #1457
This commit is contained in:
parent
ca299a097c
commit
b0d4951184
2 changed files with 9 additions and 2 deletions
|
@ -142,9 +142,11 @@ class TextHelper extends AppHelper {
|
||||||
$linkOptions .= "'$option' => $value, ";
|
$linkOptions .= "'$option' => $value, ";
|
||||||
}
|
}
|
||||||
$linkOptions .= ')';
|
$linkOptions .= ')';
|
||||||
|
$atom = '[a-z0-9!#$%&\'*+\/=?^_`{|}~-]';
|
||||||
|
|
||||||
return preg_replace_callback('#([_A-Za-z0-9+-]+(?:\.[_A-Za-z0-9+-]+)*@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*)#',
|
return preg_replace_callback(
|
||||||
create_function('$matches', '$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], "mailto:" . $matches[0],' . $linkOptions . ');'), $text);
|
'/(' . $atom . '+(?:\.' . $atom . '+)*@[a-z0-9-]+(?:\.[a-z0-9-]+)*)/i',
|
||||||
|
create_function('$matches', '$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], "mailto:" . $matches[0],' . $linkOptions . ');'), $text);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -299,6 +299,11 @@ class TextHelperTest extends CakeTestCase {
|
||||||
$result = $this->Text->autoLinkEmails($text);
|
$result = $this->Text->autoLinkEmails($text);
|
||||||
$this->assertPattern('#^' . $expected . '$#', $result);
|
$this->assertPattern('#^' . $expected . '$#', $result);
|
||||||
|
|
||||||
|
$text = "Text with o'hare._-bob@example.com address";
|
||||||
|
$expected = 'Text with <a href="mailto:o'hare._-bob@example.com">o'hare._-bob@example.com</a> address';
|
||||||
|
$result = $this->Text->autoLinkEmails($text);
|
||||||
|
$this->assertEqual($expected, $result);
|
||||||
|
|
||||||
$text = 'Text with email@example.com address';
|
$text = 'Text with email@example.com address';
|
||||||
$expected = 'Text with <a href="mailto:email@example.com" \s*class="link">email@example.com</a> address';
|
$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'));
|
$result = $this->Text->autoLinkEmails($text, array('class' => 'link'));
|
||||||
|
|
Loading…
Add table
Reference in a new issue