mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Merge pull request #3731 from cakephp/issue-3656
Fix TextHelper::autoLinkEmail() near HTML Refs #3656
This commit is contained in:
commit
282a5d1cb5
2 changed files with 66 additions and 38 deletions
|
@ -363,54 +363,82 @@ class TextHelperTest extends CakeTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* testAutoLinkEmails method
|
||||
* Data provider for autoLinkEmail.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAutoLinkEmails() {
|
||||
$text = 'This is a test text';
|
||||
$expected = 'This is a test text';
|
||||
$result = $this->Text->autoLinkUrls($text);
|
||||
$this->assertEquals($expected, $result);
|
||||
public function autoLinkEmailProvider() {
|
||||
return array(
|
||||
array(
|
||||
'This is a test text',
|
||||
'This is a test text',
|
||||
),
|
||||
|
||||
$text = 'email@example.com address';
|
||||
$expected = '<a href="mailto:email@example.com">email@example.com</a> address';
|
||||
$result = $this->Text->autoLinkEmails($text);
|
||||
$this->assertEquals($expected, $result);
|
||||
array(
|
||||
'email@example.com address',
|
||||
'<a href="mailto:email@example.com">email@example.com</a> address',
|
||||
),
|
||||
|
||||
$text = 'email@example.com address';
|
||||
$expected = '<a href="mailto:email@example.com">email@example.com</a> address';
|
||||
$result = $this->Text->autoLinkEmails($text);
|
||||
$this->assertEquals($expected, $result);
|
||||
array(
|
||||
'email@example.com address',
|
||||
'<a href="mailto:email@example.com">email@example.com</a> address',
|
||||
),
|
||||
|
||||
$text = '(email@example.com) address';
|
||||
$expected = '(<a href="mailto:email@example.com">email@example.com</a>) address';
|
||||
$result = $this->Text->autoLinkEmails($text);
|
||||
$this->assertEquals($expected, $result);
|
||||
array(
|
||||
'(email@example.com) address',
|
||||
'(<a href="mailto:email@example.com">email@example.com</a>) address',
|
||||
),
|
||||
|
||||
$text = 'Text with email@example.com address';
|
||||
$expected = 'Text with <a href="mailto:email@example.com">email@example.com</a> address';
|
||||
$result = $this->Text->autoLinkEmails($text);
|
||||
$this->assertEquals($expected, $result);
|
||||
array(
|
||||
'Text with email@example.com address',
|
||||
'Text with <a href="mailto:email@example.com">email@example.com</a> address',
|
||||
),
|
||||
|
||||
$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->assertEquals($expected, $result);
|
||||
array(
|
||||
"Text with o'hare._-bob@example.com address",
|
||||
'Text with <a href="mailto:o'hare._-bob@example.com">o'hare._-bob@example.com</a> address',
|
||||
),
|
||||
|
||||
$text = 'Text with email@example.com address';
|
||||
$expected = 'Text with <a href="mailto:email@example.com" class="link">email@example.com</a> address';
|
||||
$result = $this->Text->autoLinkEmails($text, array('class' => 'link'));
|
||||
$this->assertEquals($expected, $result);
|
||||
array(
|
||||
'Text with düsentrieb@küchenschöhn-not-working.de address',
|
||||
'Text with <a href="mailto:düsentrieb@küchenschöhn-not-working.de">düsentrieb@küchenschöhn-not-working.de</a> address',
|
||||
),
|
||||
|
||||
$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->assertEquals($expected, $result);
|
||||
array(
|
||||
'Text with me@subdomain.küchenschöhn.de address',
|
||||
'Text with <a href="mailto:me@subdomain.küchenschöhn.de">me@subdomain.küchenschöhn.de</a> address',
|
||||
),
|
||||
|
||||
$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);
|
||||
array(
|
||||
'Text with email@example.com address',
|
||||
'Text with <a href="mailto:email@example.com" class="link">email@example.com</a> address',
|
||||
array('class' => 'link'),
|
||||
),
|
||||
|
||||
array(
|
||||
'<p>mark@example.com</p>',
|
||||
'<p><a href="mailto:mark@example.com">mark@example.com</a></p>',
|
||||
array('escape' => false)
|
||||
),
|
||||
|
||||
array(
|
||||
'Some mark@example.com Text',
|
||||
'Some <a href="mailto:mark@example.com">mark@example.com</a> Text',
|
||||
array('escape' => false)
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* testAutoLinkEmails method
|
||||
*
|
||||
* @param string $text The text to link
|
||||
* @param string $expected The expected results.
|
||||
* @dataProvider autoLinkEmailProvider
|
||||
* @return void
|
||||
*/
|
||||
public function testAutoLinkEmails($text, $expected, $attrs = array()) {
|
||||
$result = $this->Text->autoLinkEmails($text, $attrs);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
|
|
|
@ -190,7 +190,7 @@ class TextHelper extends AppHelper {
|
|||
|
||||
$atom = '[\p{L}0-9!#$%&\'*+\/=?^_`{|}~-]';
|
||||
$text = preg_replace_callback(
|
||||
'/(?<=\s|^|\()(' . $atom . '*(?:\.' . $atom . '+)*@[\p{L}0-9-]+(?:\.[\p{L}0-9-]+)+)/ui',
|
||||
'/(?<=\s|^|\(|\>|\;)(' . $atom . '*(?:\.' . $atom . '+)*@[\p{L}0-9-]+(?:\.[\p{L}0-9-]+)+)/ui',
|
||||
array(&$this, '_insertPlaceholder'),
|
||||
$text
|
||||
);
|
||||
|
|
Loading…
Add table
Reference in a new issue